Use the one parameter in other pages with Laravel?

Asked

Viewed 295 times

0

I’m doing an app on Laravel 5.4 that the administrator modifies various information of a particular client.

Example: in the customer listing is clicked on Modules inserir a descrição da imagem aqui

The user is directing to another page, which is environment that will list, modify, etc. All information of each module of this client. inserir a descrição da imagem aqui

But my problem is that I’m having to pass the ID of the client on all pages, by URL.

Example:

admin/modules/1/financial/data '1' is the client ID.

Or

admin/modules/1/supplier/data '1' is the client ID.

I was going to try to use the Service Container of Larable, but I could not understand how to do this in my application.

  • Could I explain the last part more clearly? it is worth remembering that it is normal to make so clear it will depend on a better context, but, if you can clarify the last part !!!

  • I would like to pass the parameter a single time, like when I will open the page of a module I have to take the parameter of the client ID, this will occur on all pages of the modules. I read something about English, but I couldn’t understand how to implement it.

  • Let’s see if I understand, that tab you click and pass one after the other with an address ? and at that address is loaded the page again and has that id that so bothers you to be passed?

  • that! equal admin/modules/1/financial is a module admin/modules/1/supplier another module, each is a different tab.

  • is just like this has no better form, you will create a Singleton so that, if you will create a session or a cookie for that, if the element in the url already satisfies you and does not consume resources. in my experience it’s just like that ...

  • Why don’t you improve the interface and load this information right away?

  • I thought about doing this, but there are many modules, the page will be huge, and take a long time to load

  • I thought there would be another way to do this, without having to pass the ID parameter all the time in the URL

  • Got it man ... well I guess it’s not necessary to do something different ... but, I don’t know! each one has their own experience and opinion ...

  • Okay! Thanks anyway. I think I’ll continue the same way I’m doing anyway!

  • Show how is the route you are setting, and the controller method.

  • route Route::get('{cid}/financeiro', ['as' => 'financial.index', 'uses' => 'MfinancialController@index']);

  • Controller public function index($cid)
 {
 $client = $this->userRepository->find($cid);

 return view('admin.modules.financial.index', compact('client'));
 }

Show 8 more comments

1 answer

0

Expensive a way for you to implement what you want is to pass the id through the session

session(['cliente'=>'valor do id']);

and at the end of the last module when it is saved you can use

$id = session()->pull('cliente');

this method pull() will take client out of session and pass to the $id

  • But can I change that ['client'] Yes? type when I click the Module of the second client it will already assign a new value to the Session['client'] ??

  • yes, if you call this function in the method that starts the module .

  • public function index($id)
 {
 session(['cid' => $id]);
 $client_Id = session()->pull('cid');

 // dd($client_Id);
 $client = $this->userRepository->find($client_Id);
 return view('admin.modules.index', compact('client'));
 }

  • I did so but when it was in another window to fetch the Séssion, came the value, could you give me an example??

  • Implementing by the session is not the right way to solve the problem. If the user opens for example two windows, one for each client, you would have problems.

  • is in this case the various windows would not work , what could do is use a check for if already have the client in session it would not change would continue with the same

  • is I dismissed that idea.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.