dimanche 5 août 2018

Laravel Variables across Layouts need correct route

I have a side bar displaying users in a laravel layout. I want the sidebar to link to the id for the user's edit page when I click the link so that the variables can be passed to all user pages. How do I create an edit route for this? I really just need the best way to create an edit route instead of a display route, which is what I settled on initially but is causing me problems because I want to edit by the id. The current route is giving me a name in the URL and when I try to edit/delete/update it can't find the id because the URL is displaying the name.

includes.user_sidebar

<div class="navbar-default sidebar" role="navigation">
        <div class="sidebar-nav navbar-collapse">
            <ul class="nav" id="side-menu">
                <li class="sidebar-search">
                    <div class="input-group custom-search-form">
                        <input type="text" class="form-control" placeholder="Search...">
                            <span class="input-group-btn">
                                <button class="btn btn-default" type="button">
                                    <i class="fa fa-search"></i>
                                </button>
                            **</span>
                    </div>
                    <!-- /input-group -->
                </li>
                @if($users)
                    @foreach($users as $user)
                <li> 
                <a href=""></a>
                </li>
                @endforeach
                    @endif**


                    <!-- /.nav-second-level -->
                </li>
                <li class="active">
                    <a href="#"><i class="fa fa-files-o fa-fw"></i> Sample Pages<span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level">
                        <li>
                            <a class="active" href="blank.html">Blank Page</a>
                        </li>
                        <li>
                            <a href="login.html">Login Page</a>
                        </li>
                    </ul>
                    <!-- /.nav-second-level -->
                </li>
            </ul>


        </div>
        <!-- /.sidebar-collapse -->
    </div>
    <!-- /.navbar-static-side -->
</nav>


<?php

Controller

class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $roles=Role::pluck('name', 'id')->all();

       $users = User::all();

       $accountReps= AccountRep::pluck('name', 'id')->all();

        return view('users.index', compact('users', 'accounts', 'roles', 'accountReps'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
        $users = User::all();
        return view('users.create', compact('users', 'accounts', 'roles', 'accountReps'));




    public function edit($id)
    {
        $user = User::findOrFail($id);

          $users=User::distinct()->orderBy('name', 'asc')->get();



        return view('users.edit', compact('user');



    }


    public function update(UsersEditRequest $request, $id)
    {
        //





        $user = User::findOrFail($id);


        if(trim($request->password) == ''){

            $input = $request->except('password');

        } else{


            $input = $request->all();

            $input['password'] = bcrypt($request->password);

        }








        $user->update($input);


        return redirect('/users');



    }


    public function destroy($id)
    {
        //
    }


}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire