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