Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z dodaniem nowych rekordów do bazy danych [Laravel]
klopot21
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 1.06.2020

Ostrzeżenie: (0%)
-----


Cześć,
Dziś chciałem dodać nową tabelę do bazy danych a następnie ją uzupełnić niestety od 5 godzin nie jestem w stanie tego zrobić może ktoś mi wyjaśni o co chodzi?

Migracja
  1. <?php
  2.  
  3. use Illuminate\Database\Migrations\Migration;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Support\Facades\Schema;
  6.  
  7. class site extends Migration
  8. {
  9. /**
  10.   * Run the migrations.
  11.   *
  12.   * @return void
  13.   */
  14. public function up()
  15. {
  16. Schema::create('site', function (Blueprint $table) {
  17. $table->id();
  18. $table->string('link');
  19.  
  20.  
  21. });
  22. }
  23.  
  24. /**
  25.   * Reverse the migrations.
  26.   *
  27.   * @return void
  28.   */
  29. public function down()
  30. {
  31. Schema::dropIfExists('site');
  32. }
  33. }



  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Illuminate\Database\Eloquent\Model;
  6.  
  7. class site extends Model
  8. {
  9. public $timestamps = false;
  10. }



  1. use App\site;
  2.  
  3.  
  4.  
  5. $rules = [
  6. 'site_link' => 'required',
  7. 'site_description' => 'required',
  8. 'rating' => 'required',
  9. ];
  10.  
  11. $customMessages = [
  12. 'site_link.required' => 'Wymagany link do strony!',
  13. 'site_description.required' => 'Wymagany opis strony!',
  14. 'rating.required' => 'Wymagana ocena strony!'
  15. ];
  16.  
  17. $this->validate($request, $rules, $customMessages);
  18.  
  19. $site_link = $request -> input('site_link');
  20. $site_description = $request -> input('site_description');
  21. $rating = $request -> input('rating');
  22.  
  23. $site = new site;
  24. $site->link = "1";
  25. $site->save();
  26.  
  27.  
  28.  
  29.  
  30.  
  31. if(isset($last_id_db)) {
  32.  
  33. return redirect()->back()->with('msg_success', 'Dodałeś Nową stronę!<br>');
  34. }
  35. else
  36. {
  37. return redirect()->back()->with('msg_errors', 'Błąd dodawania nowej strony. Prosimy o kontakt z administratorem.');
  38. }
  39.  
  40.  
  41. }
  42.  
  43.  
  44.  


Jeśli uzyję bazy danych która istniała wcześniejszej nie ma problemu. po modyfikacji kodu można bez problemu dodać nowe rekordy problem niestety występuje tylko w przypadku próby dodania danych do nowej tabeli.

Sprawdziłem przez phpmyadmin czy tabela "site" znajduje się w bazie danych i wszystko jest okey. Jeśli dodam rekordy ręcznie w bazie i chce je pobrać to nie ma problemu problem pojawia się przy próbie dodania...

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'videoweb.sites' doesn't exist (SQL: insert into `sites` (`link`) values (1))

W bazie danych videoweb istnieje tabela site natomiast nie wiem skąd bierze się "s" na końcu. w błędzie który wyświetla ralavela.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 00:39