Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

rozsazoltan/example-laravel-bread

Repository files navigation

Example for BREAD making with Laravel Framework

rozsazoltan - example-laravel-bread License

B = BROWSE -> can show all exists records (in table)

R = READ -> can show exists record (can find more information)

E = EDIT -> can update exists record (form)

A = ADD -> can add new record (form)

D = DELETE -> can delete record (just a function, can call with "trash" button)

Build database structure

Use migrations to build. php artisan make:migration {name}

Example: php artisan make:migration create_phonebooks_table

If you use laravel standards: table name is always plural, and model name is always singular

More information for Migrations

Make models for tables

Use Eloquent to table management. Eloquent safer than native SQL codes. php artisan make:model {name}

Example: php artisan make:model Phonebook

More information for Eloquent and Models

Make Controller

In controller you can define your methods. For example: What need working, if you need all records in table. You need all records, and need view a blade. php artisan make:controller {name}

...
public function show() {
    // Get all record as Array
    $items = Phonebook::get();
    
    // Return with blade (in resources/views/phonebook/index.blade.php), and give all record to blade as 'phonebooks'.
    // If you write your blade you can call all record as $phonebooks
    return view('phonebook.index')->with('phonebooks', $items);
}
...

More information for Controllers

Make Routes

If you call a link from browser header then laravel try find it in routes. If can't find it, laravel return error 404 page. If find it, laravel just will run associated command.

You can add routes in ./routes folder. Default routes can find in ./routes/web.php file.

Route::get("test", function() {
    echo "Now testing...";
});

Now if you call http://localhost:8000/test, laravel will echo Now testing... text.

More information for Routes

Make Blade files

Now just you need blade files. Here can use html, js and css codes for better result. All blades can find in ./resources/views folder. If you need view a blade, just run return view({name}).

Example: return view('phonebook.index'), will return ./resources/views/phonebook/index.blade.php for us.

More information for Blade

About

Example for BREAD making with Laravel Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published