Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

php - In Laravel how to make Mutiple Dashboards for different clients names?

I am new to Laravel. I am trying to understand the concept of making Multiple Dashboards for different clients names? I currently have a drop down using a the below:

<div class="select_dropdown">
  <select class="select" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
                        <option disabled selected>Clients</option>

    @foreach($clients as $client)
    <option value="/dash/{{$client->ID}}"> {{$client->Name}} </option>
    @endforeach

   </select>
</div>

This is within the app.blade.php which is part of the UI that exists on every page.

Next I have a Route within the wep.php file that has :

Route::get('/dash/{id}', 'DashController@index');

Then I have a controller that reads:

public function index() { 
        
        return view('dash.maindash');

    }

I was able to use :

@if (Request::is('dash/1'))  
Page using a if Statement within html
@endif

To change what the user sees based on the URL but there are multiple clients to choose from. Would it be normal to have multiple if statements to do this or am I doing to much manual style work here? Also Am I using the Select Tag properly to select and change the URL ? I am not sure if this approach is right and i am missing some important routing concepts.

question from:https://stackoverflow.com/questions/66048356/in-laravel-how-to-make-mutiple-dashboards-for-different-clients-names

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

well, you are passing id of client in a route i.e

Route::get('/dash/{id}', 'DashController@index');

Now in controller , get that id:

public function index($id) { 
       $client_id = $id;
// now u can fetch details of client having passed id and u can pass that in view using compact
        $client_details = [
             'data' => 'goes here',
        ];
        return view('dash.maindash',compact('client_details'));

    }

In maindash.blade.php: you can dynamically render details of client therefore there will be different dashboard for client. E.g:

<p>Client name: {{ $client_details['name'] }}</p>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...