Laravel CRUD Operation with File Upload
Welcome to the 11th chapter of Being an Artisanary. In show CRUD(create-read-edit-delete) operation with file upload. So if you already complete the previous chapters/sections, then you're good to go, if not my recommendation would be please complete the previous chapters. Because we'll use the same old repository.
Note: Tested on Laravel 10.0
- Install Image Intervention for Image Processing
- Create and Setup a Repository
- Create and Setup Observer
- Create and Setup the Controller
- Setup Model and Migration
- Define Routes
- Create and Setup View
- Output
Image intervention is one of the most used packages for image processing. For installing image intervention fire the below command in the terminal.
And it'll be enough, no need to do anything.
At first, we'll create a repository class called BlogRepository.php where we'll write our all database logic so that we can use the same query everywhere.
We'll already discussed what is Observer and why we use observer, so I'll not repeat here.
Then, we'll create a controller called BlogController.php where we'll write our logic or insert the data. So, fire the below command in the terminal.
It'll create a file under app\Http\Controllers called BlogController.php. Now open the file and replace it with the below codes.
Now we'll set up our model and migration file. And we also discuss each attribute that we going to use there in the previous lecture. So I don't want to repeat it here.
Put these routes in web.php.
The whole file will look like the below
So at first, we'll create a blade file where we put our flash messages which we discuss in our previous chapter. And later we'll just @include() on every page.