Jahid26 Jahid26 - 3 months ago 6
MySQL Question

Route Id Not working

I am creating a project called doctor management system. I am now stuck in this that when a user logged in his page my route function get the specific id & then show his information. But when I logged in it did not get id & that's why it put some error but When I manuaaly enter the id it worked perfectly ok. I did not find why this occurs. Please Guys Help Me.

My Route File

Route::group([
'middleware' => 'auth'
], function() {


Route::get('/home/{profile_id}', [
'as' => 'admin',
'uses' => 'AdminController@index'
]);

Route::get('/profile/{profile_id}', array('as' =>'profile' ,'uses' => 'ProfileController@index'));


My profile Controler is

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;

class ProfileController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/

public function index($profile_id)
{
$profile = User::find($profile_id);
// if(!$profile) {
// return redirect()->route('logout')->with(['fail' => 'Profile Not Found']);
// }
return view('admin.article.index',['profile' => $profile]);
}


The error is
enter image description here

Answer

You did not specify what URL is being accessed, so I suppose it is whatever_your_domain_is/profile/{id}.

The error being presented is telling you there is no route for the URL being entered.

I suppose you wanna show the profile for logged-in user, so actually you don't need any {id} in route, you can:

$profile = Auth::user();
return view('admin.article.index', compact('profile'));

But if you do want to show other user's profile, just check out your URL.

Some things I've noticed:

Your 'profile/{profile_id}' route is outside of Route group, that's the way it is supposed to be?

Choose a single pattern to write your code. You've written array using to different notations: array() and []. Read about Coding Stardards (e.g. https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).