Wednesday, December 26, 2018

Create simple CRUD using Laravel 5.7 (Part 4 - Modify Controller, Model and Create route)


Hey guys...Welcome back. Today we are going to create controller and modal file in Laravel. In the controller file, you can see after we generate it automatically there are created the main function for the CRUD automatically. There are seven functions include index, create, store, show, edit, update, destroy functions. In our blade templates we are link the templates with these functions using the route keyword. You can see it when you carefully look the code. OK... Now we going to modify these functions according to our requirements what we want to do with these functions.
Let’s take one by one.


  • First open the  the index function. We need to load the index page using this functions.








  • Then create function. We need to display the page that add new student details.







  • Then we have the store function to store the data in database.















  • Now we have the show function for display the data that store in the database.



  • In edit function we need to display the details edit form page.







  • Next using the update function we can update the data.














  • Finally we can destroy the data from the database.











These are the main operations that we have to include in the CRUD controller.


Now we need to modify the model page for make the connection with database.
For it you can use the file app->Student file.
Add  ' protected $fillable = ['name''age']; '  to the model class.  

OK..now work is complete with the controller and model page sides.

Now is the important thing to do. That is create the route for run the project. Basically there are many more routes for our requirements. For now we use the web route for our project. You can see the web route in your routes folder. Open the ‘ web.php ‘ file. Then create the simple route for the project.

Add line ' Route::resource('students','StudentController'); ' to the web.php file to built a route.

At last we come to the end of our session. Now we have to run the project. Open a command prompt. Got to the project folder.

' cd\'
' cd\xampp\htdocs\MyFirstPro\blogs '

Then type ' php artisan serve '. Now open any web browser and type ' localhost:8000/students ' on the address bar. bingo...you can run your CRUD now.

We are complete coding  a CRUD using Laravel 5.7. You can try a new one your own. You can download the project from https://github.com/Dilank/Simple-CRUD-using-Laravel-5.7.git. Thank you for join my tutorial blog series. Hope it will help you. Also hope your comments. We will meet another tutorial series then. Bye.. 😊👋


No comments:

Post a Comment

Create simple CRUD using Laravel 5.7 (Part 4 - Modify Controller, Model and Create route)

Hey guys...Welcome back. Today we are going to create controller and modal file in Laravel. In the controller file, you can see after we g...