MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

How to implement CRUD functions in the Laravel PHP Framework? Part-2

How to implement CRUD functions in the Laravel PHP Framework?

In previous blog Part-1, We have seen that how we start to implement CRUD functions.

Step 12. Now, Go to app/Http/Controllers/CustomerServiceController.php. Here, we’ll see all predefined Crud function, so we have to write code only for CRUD to display view file in the browser within Create() function, and to insert data into the Mysql table within Store() function.

public function create()
    {
        return view('service.create');
    }
Code language: PHP (php)
ServiceController.php with the create() function returning the service.create view highlighted
ServiceController store() function validating service_name, saving a Service and redirecting with success

Step 13. Go to routes/web.php file ,we have to define route of this all CustomerServiceController CRUD functions.

Route::resource('service','ServiceController');Code language: PHP (php)
Routes/web.php with Route::resource('service', 'ServiceController') highlighted

Step 14. Go to app/Service.php. Now, we need to list all the properties we need in the $fillable array.

App/Service.php model extending Eloquent Model with service_name in the $fillable array

Step 15. Go to app/Http/Controllers/ServiceController.php file and write following codes within index() function.

 public function index()
    {
       $services = Service::all()->toArray();
        return view('service.index', compact('services'));
    }
Code language: PHP (php)
ServiceController index() function fetching all services and returning the service.index view

Step 16. To update Mysql table data, we have to make an edit link in resource/views/Service/ folder. So, create an index.blade.php file.

Index.blade.php showing a table of service names with Add button and Edit links

Step 17. Go to resources/views/Service folder and create edit.blade.php file. In this file, service data will be loaded.

Edit.blade.php with a PATCH form to update service_name via ServiceController@update

Thanks

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

How to Delete Multiple Records using Checkbox in Laravel?

It’s almost need to give feature for remove multiple records using checkbox, if you are developing e-commerce application or any big web application then you must give…

Read More

How to merge two or multiple tables to each other in the Laravel PHP Framework? (Part-3)

Part-1 Part-2 Now, we’ll create the 2nd table State to merge with the Country table. Step 1. Create child file resources/views/State folder with name create.blade.php. Step 2. Create edit.blade.php file. In this…

Read More

How to Use Search Functionality with Pagination in Laravel PHP Framework? Part 1

How to use Search Functionality with Pagination in Laravel PHP Framework? We are going to use Search Functionality with Pagination within the CRUD table. Click for the…

Read More

How to implement CRUD functions in the Laravel PHP Framework? Part-3

How to implement CRUD functions in the Laravel PHP Framework? In previous blog Part-2, We have seen create() store() and index() functions. Step 18. Go to app/Http/Controller/CustomerServiceController.php and in that…

Read More

Python Tutorials: Database operations using python – mysql

This tutorial connects Python to MySQL with the official mysql-connector-python driver and runs the full set of CRUD operations: create a database and table, then insert, read,…

Read More

Laravel breeze vs laravel fortify comparison

Here’s a comparison table between Laravel Breeze and Laravel Fortify to help you understand their differences and choose the right tool for your project: Feature Laravel Breeze…

Read More