0

When I click "Profile" in home.blade.php I am having an error, "Missing 1 argument for App\Http\Controllers\ProfileController::show()" how to solve this error?

home.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="sidebar col-md-3">
            <div class="panel panel-default">
                <div class="panel-heading">Navigation</div>
                  @if (Auth::user()->type === "Admin")
                    <ul class="list-group">
                        <li class="list-group-item"><a href="{{ URL::to('users') }}">Users</a></li>
                        <li class="list-group-item"><a href="{{ URL::to('adlogs') }}">Logs</a></li>
                    </ul>
                 @elseif (Auth::user()->type === "Employee")
                    <ul class="list-group">
                        <li class="list-group-item"><a href="{{ URL::to('profile') }}">Profile</a></li>
                        <li class="list-group-item"><a href="{{ URL::to('logs') }}"> Logs</a></li>
                    </ul>
                @else

                @endif
            </div>
        </div>  
        <div class="col-md-9">
            <div class="panel panel-default">
                <div class="panel-heading">Dashboard</div>

                <div class="panel-body">
                    You are logged in!
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

Route:

Route::get('/home', 'HomeController@index');
Route::resource('/profile', 'ProfileController@show');

HomeController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        return view('home');
    }

}

ProfileController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
class ProfileController extends Controller
{

    public function index()
    {

    }


    public function create()
    {
        //
    }


    public function store(Request $request)
    {
        //
    }


    public function show($id)
    {
        $users = User::find($id);

        return view('profile.index',compact('users'));


    }


    public function edit($id)
    {
        //
    }


    public function update(Request $request, $id)
    {
        //
    }


    public function destroy($id)
    {
        //
    }
}

and this is index.blade.php of Profile folder. This is where should be the output.

@extends('layouts.app')
@section('content')
    <div class="container">
        <div class="row">

            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <td>User ID</td>
                        <td>First Name</td>
                        <td>Last Name</td>
                        <td>Email</td>
                        <td>Job Title</td>
                        <td>Contact No</td>
                        <td>ABN Number</td>
                        <td>Status</td>
                        <td>Type</td>
                        <td>Action</td>
                    </thead>
                    <tbody>                                     
                        @foreach($users as $value)  
                            <tr>
                                <td>{{ $value->id }}</td>                           
                                <td>{{ $value->first_name }}</td>
                                <td>{{ $value->last_name }}</td>
                                <td>{{ $value->email }}</td>
                                <td>{{ $value->job_title }}</td>
                                <td>{{ $value->contact_no }}</td>
                                <td>{{ $value->abn_number }}</td>
                                <td>{{ $value->status }}</td>
                                <td>{{ $value->type }}</td>
                                <td>
                                    <a href="{{ URL::to('users/' . $value->id . '/edit') }}">
                                        Edit
                                    </a>                                                    
                                    <a href="{{ URL::to('users/' . $value->id . '/destroy') }}">
                                        Delete
                                    </a>
                                </td>   
                            </tr>                   
                         @endforeach                                         
                    </tbody>
                </table>
            </div>



        </div>
    </div>
 @endsection

How to solve this problem?

5
  • Why laravel 5.3? The current version is 5.5 Commented Sep 14, 2017 at 8:11
  • this is what the client wants Commented Sep 14, 2017 at 8:13
  • how to solve this problem man? Commented Sep 14, 2017 at 8:14
  • 5.3 was released on 23 Aug 2016, long time ago Commented Sep 14, 2017 at 8:26
  • Define individual routes for every method instead of using route resource Commented Sep 14, 2017 at 8:59

4 Answers 4

3

This situation will have much solution.

Solution number one

You can change the route look like this

Route::resource('/profile/{id}', 'ProfileController@show');

Solution number two

Used the same route and you can change your controller looks like this

public function show()
{
    $id = Auth::id();
    $users = User::find($id);

    return view('profile.index',compact('users'));

}

i hope this anwers can help your problems

Sign up to request clarification or add additional context in comments.

6 Comments

i am having an error: Route pattern "/profile/{id}/{{id}}" cannot reference variable name "id" more than once.
this doesn't work with Route::resource because with resource you cannot use route placeholders
You can try to used like this, Route::resource('user', 'AdminUserController', ['parameters' => [ 'id' => 'admin_id' ]]);
Your resource route is wrong and you are waisting a lot of resources by your way of fetching the authenticated user (hint: Auth::user() is a thing)
No, used $id = Auth::id(); is for get the currently authenticated user's ID. And we don't need to send that again from get url
|
2

When using

Route::resource...

you can't specify a function. Just use:

Route::resource('/profile', 'ProfileController');

EDIT:

Route::resource creates 6 routes for you. See my image below.


As your route needs a parameter (the $id) you need to pass it a parameter. Maybe it's easier to use named routes also. So instead of

<a href="{{ URL::to('profile') }}">Profile</a>

you would write

<a href="{{ route('profile.show', Auth::user()->id) }}">Profile</a>


You can see all available routes with the command

php artisan route:list

The output should look like this: artisan route:list output

9 Comments

problem still not solved. i remove the @show and it has no output. and when i use "get" instead of "resource" i still get the same error, "Missing 1 argument"
if use get u need to pass id value wich u use show($id) route be like Route::get('/profile/{id}', 'ProfileController@show');
i use your method and i get another error: NotFoundHttpException in RouteCollection.php line 161:
NotFoundHttpException means that there is no route defined. Have you defined Route::resource('/profile', 'ProfileController'); in your routes/web.php?
@PKeidel profile.show is not visible in name column while using route list
|
0

here is the route list

profile{id} has no name in it

Comments

0

in route

Route::resource('/profile', 'ProfileController');    

in view

     <ul class="list-group">
      <li class="list-group-item"><a href="{{ URL::to('profile/'.Auth::user()->id)}}">Profile</a></li>
      <li class="list-group-item"><a href="{{ URL::to('logs') }}"> Logs</a</li>
    </ul>

eg. $id may be 1, then it will be routed to the show method in ProfileController.php

             public function show($id){
                    $users = User::find($id);
                    return view('profile.index',compact('users'));
                }

2 Comments

there is an error: Undefined variable: id (View: C:\xampp\htdocs\DTR\resources\views\home.blade.php)
you must pass $id to the view, actually i meant by profile id, public function index() { $id = Auth::user()->id; return view('home', compact('id')); } or use can use directly in view, like <ul class="list-group"> <li class="list-group-item"><a href="{{ URL::to('profile/'.Auth::user()->id)}}">Profile</a></li> <li class="list-group-item"><a href="{{ URL::to('logs') }}"> Logs</a</li> </ul>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.