It is actually a set of factors at the beginning routes that are configured with the verb
, POST
, GET
, DELETE
, PUT
), example
Route::get('/exemplo', "ExemploController@index");
Route::post('/exemplo', "ExemploController@index");
This means that the /exemplo
address accepts requests configured in the route file verb
POST
and GET
and in laravel by classe
Request
I can define multiple 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';
}
}
}
Laravel can work that way?
Can , but, I would not recommend, for several reasons, one of them and the amount of code it solves.
several issues breaking an Object Guidance rule that is a single responsibility, where one party solves a particular problem, in the example case presented, is already solving two, and may even be worse if this code has to be changed and grow. Maintenance with this becomes difficult and critical at various times of coding.
The laravel facilitates these types of requests, where several pages access the same controller
and request
should be done for page that made the request as in the example above?
R Yes , it is very easy to work with requisitions and together with the routes take advantage of and several times the
19.10.2016 / 17:53