Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 2.06 KB

LARAVEL.md

File metadata and controls

80 lines (59 loc) · 2.06 KB

Laravel Basics

Creating Models along with migrations

php artisan make:model Note -m

Creating Controller

php artisan make:controller NoteController --resource --model=Note

Creating View

php artisan make:view note.index

Creating Factory

php artisan make:factory NoteFactory --model=Note

Migrating and seeding default data

php artisan migrate:fresh --seed

Making routes via resources

Route::resource('notes', NoteController::class);

This will generate all following

    Route::get('/notes', [NoteController::class, 'index'])->name('notes.index'); // List all notes
    Route::get('/notes/create', [NoteController::class, 'create'])->name('notes.create'); // Show form to create a new note
    Route::post('/notes', [NoteController::class, 'store'])->name('notes.store'); // Store a new note
    Route::get('/notes/{note}', [NoteController::class, 'show'])->name('notes.show'); // Show a specific note
    Route::get('/notes/{note}/edit', [NoteController::class, 'edit'])->name('notes.edit'); // Show form to edit a specific note
    Route::put('/notes/{note}', [NoteController::class, 'update'])->name('notes.update'); // Update a specific note
    Route::delete('/notes/{note}', [NoteController::class, 'destroy'])->name('notes.destroy'); // Delete a specific note

Passing multiple variables to a page

    return view('dashboard', [
        'studentCount' => $studentCount,
        'classCount' => $classCount,
        'subjectCount' => $subjectCount,
    ]);

Grouping routes

    Route::middleware(['auth', 'verified'])->group(function () {
        Route::resource('class', ClassController::class);
        Route::resource('student', StudentController::class);
        Route::resource('subject', SubjectController::class);
    });

Hidden fields

Hidden fields are not returned by server. To implement this in Laravel, you can use the following code in your Model:

    protected $hidden = [
        'password',
        'remember_token',
    ];