Questions about requests and returns

1

I have 2 different pages that access the same control. The idea is that I retrieve which page made the request, because depending on what it takes the two different returns.

Ex.

I have a button to send a product to the cart, but this one button is on index (home page) and the other is on the product description. If I click the index button, it should redirect me to index itself but incrementing the item to the cart, since if I am in the product details it should redirect me to the product details.

  • Does Laravel facilitate these types of requests, where multiple pages access the same controller and request should be done for page that made the request as in the example above?
  • asked by anonymous 19.10.2016 / 17:00

    1 answer

    1

    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 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 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