The document describes various Laravel commands for creating projects, models, migrations, controllers, factories, seeders and relationships. It also covers CRUD operations and using Breeze for authentication.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
213 views7 pages
Laravel Resume
The document describes various Laravel commands for creating projects, models, migrations, controllers, factories, seeders and relationships. It also covers CRUD operations and using Breeze for authentication.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7
Les commandes est les methods : laravel
create projet => composer create-project laravel/laravel example-app
lancer projet => php artisan serve create model => php artisan make:model Test create controller => php artisan make:controller TestController -r create migration => php artisan make:migration create_test_table Pour ajouter la table Pour suprimer la table
return new class extends Migration{ public function down(){
public function up(){ Schema::dropIfExists(‘test’); Schema::create(‘test’,function(Blueprint $table){ } $table->id(); … autre column } $table->timstamps(); }) }
ajouter column a table => php artisan make:migration add_column_to_test_table --table=test
public function up(){ Schema::tabel(‘test’,function(Blueprint $table){ $table->string(‘nom_column’); }) } ajouter foreign key a table => php arisan make:migration add_column_id_to_test_table --table=test Public function up(){ Schema::table(‘test’,function(Blueprint $table){ $table->unsignedBigInteger(‘column_id’); $table->foreign(‘column_id’)->references(‘id’)->on(‘nom_tabel’) }) } supprimer column a table => php artisan make:migration remove_column_from_test_table --tale=test Public function up(){ Schema::table(‘test’,function(Blueprint $table){ $table->dropColumn(‘column’); }) } create model avec migration => php artisan make:model Test -m create model avec migration et controller => php artisan make:model Test -mcr create seeder => php artisan make:seeder TestSeeder Avec factory Class TestSeeder extends Seeder Class TestSeeder extends Seeder Public function run(){ Public function run(){ DB::table(‘test’)->insert([ Test::factory(n fois)->create() ‘nom’=>’moussan’, } … autre data ]) n fois = 10 or 20 … } create factory => php artisan make:factory TestFactory –model=Test Class TestFactory extends Factory{ Public function definition(){ return[ ‘nom’=>fake()->name(), … autre column ] } } Run seeder => php artisan db:seed –class=TestSeeder | php artisan db:seed Empty database and run seeder => php artisan migrate:fresh --seed create request => php artisan make:request TestRequest create middleware => php artisan make:middleware TestMiddleware Method handel Method terminate Public function handle(Request $request , Closure Public function handle(Request $request , Response $next){ $response){ Return $next(request) } } Routes => Pour lister la vue index Route::get(‘/index’,[nom_controller,’index])->name(‘index’) Pour la vue show Route::get(‘/show/{test},[nom_controller,’show’])->name(‘show’) Pour ajouter la vue create Route::get(‘/create’,[nom_controller,’create’])->name(‘create’) Pour modifier la vue edite Route::get(‘/edit/{test}’,[nom_controller,’edit])->name(‘edit’) Pour souvgarder Route::post(‘/store’,[nom_controller,’store’])->name(‘store’) Pour update Route::update(‘/update/{test}’,[nom_controller,’update])->name(‘update’) Pour delete Route::delete(‘/destroy/{test},[nom_controller,’destroy’])->name(‘destroy’) Pour voire tout ca dans une route Route::resources(‘/test,nom_controller) Relationships => BelongsTo | HasMany class Habitan extends Model { class Ville extends Model { Public function villes() :BelongsTo Public function habitans() :HasMany { { Return $this->BelongTo(Ville::class); Return $this->HasMany(Habitan::class); } } } }
Importes namespace =>
App\Http\Controllers | App\Http\Middleware App\Models database\migrations | factories : database\factories | seeders : database\seeders resources/views routes=>web | console | api | channels store() and update() photo => Dans le form create on ajouter attribute Dans le form edite on ajouter attribute enctype=”multipart/form-data” enctype=”multipart/form-data” Store() Update() $newtest = $request->file(‘photo’)- If($request->hasFile(‘photo’)) >store(‘dossier’,’public’) { $newtest = $request-> file(‘photo’)->store(‘dossier’,’public’) } Laravel Breeze=> 1 : composer require laravel/breeze | 2 : php artisan breeze:install 3 : php artisan migrate | 4 : npm install | 5 : npm run dev CRUD => public function index(){ $villes = Ville::all() return view('villes.index',compact('villes')) } public function create(){ public function store(Request $request){ return view('villes.create') $newVille = new Ville(); } $newVille->nom = $request->nom $newVille->save() return redirect()->route('villes.index') }
public function show(Ville $ville){
return view('villes.show',compact(‘ville’)) } public fuction edit(Ville $ville){ public function update(Request $request , Ville return view('villes.edit',compact(ville)) $ville){ } $ville->nom = $request->nom $ville->update() return redirect()->route('villes.index') }