Warm tip: This article is reproduced from stackoverflow.com, please click
laravel laravel-5

Laravel do i need two controllers to handel two store functions?

发布于 2020-03-31 22:59:22

Basically what i want to do is that 1 Controller handels two store functions called like this:

public function singleupload(){

..some code
}

and

public function multiupload(){
..some code too
}

as i continued to define the routes (get/post)

Route::get('/MultiUpload', 'controller@MultiUpload');
Route::get('/SingleUpload', 'controller@SingleUpload');

Route::post('/MultiUpload', 'controller@storeMulti');
Route::post('/SingleUpload', 'controller@storeSingle');

and as i tried to post some data to my database it tells me that there is no 'store' function. So i opened the docs and found this:

POST    /photos store   photos.store

So my question is can i create two store functions in one controller or do i have to create a different one so every route has its own controller with its own store function?

Questioner
Zedex
Viewed
20
saurabh kamble 2020-01-31 20:09

You are doing some things wrong.

First of all follow Repository Pattern.

You should always write all common functions in Repository which can be accessible in entire Project.

You should use controller only to fetch the request from the Route and pass all the logic to the Repository.

These Process will help you reduce all you coding lines.

Hope this helps !!!

cheers!!