In fact it is a set of factors at first the routes that are configured with the type of verb
(POST
, GET
, DELETE
, PUT
), example:
Route::get('/exemplo', "ExemploController@index");
Route::post('/exemplo', "ExemploController@index");
that means the address /exemplo
accepts requests configured in the route file verb
POST
and GET
and in the Larable for classe
Request
I can define various behaviors within an action (Action
) of controller
, example:
class ExemploController extends Controller
{
public function index(Request $request)
{
//dependendo do verb eu faço determinada operação.
if ($request->isMethod('get'))
{
return view('empresafuncao');
}
if ($request->isMethod('post'))
{
return 'post';
}
}
}
The Laravel can work that way?
R. Can, but, I wouldn’t recommend, for several reasons, one of them and the amount of code that solves several problems by breaking a Object Orientation which is sole responsibility, where a party solves a particular problem, in the case example presented, is already solving two, and may even get worse if this code has to be changed and grow. Maintenance with this becomes difficult and critical at various times of coding.
The Larable facilitates these types of requests, where multiple pages access the same controller
and the request
should be made to page that made the request as in the example above?
R. Yes, it is very easy to work with requests and together with the routes take profits and various moments, the relationship of the request
is that, can make the request to the same page, but it is not recommended as already explained in that reply.
Ideally, each request has its own Action/Controller
and its associated type of request (verb
), where the process is very clear to solve a particular problem.