Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vandan's avatar
Level 13

Route pattern "/pg/profile/{id}/{{id}}" cannot reference variable name "id" more than once.

here is my blade file

<a href="{{route('document_delete',$list->pg_id)}}"></a>

controller file

public function destroy($id)
    {
        $doc = Pg::where('id',$id)->first();    
        $document = Document::where('pg_id',$doc->id)->first();    
        $doc_path = public_path().'/PG/Doc/'.$id.'/'.$doc->multiple_doc;  // Value is not URL but directory file path
        if(File::exists($doc_path)) {
                File::delete($doc_path);
        }
        $document->delete();
        notify()->success('Profile Document Remove Successfully !');
        return \Redirect::route('profile',['id'=>$doc->user_id]);        
    }

route file

Route::resource('pg/document/{id}', 'pages\DocumentController',['names'=['store'=>'documentmodal_store','destroy'=>'document_delete']]);

i dont know resource route how to pass id when data delete

0 likes
27 replies
manelgavalda's avatar

The resource routes will automatically create the route pattern with the variables in place, so you don't need to add the $id in the route:

Route::resource('pg/document', 'pages\DocumentController')
->names(['store'=>'documentmodal_store','destroy'=>'document_delete']);
vandan's avatar
Level 13

@manelgavalda

Too few arguments to function App\Http\Controllers\pages\ProfileController::store(), 0 passed and exactly 1 expected

so error fire

manelgavalda's avatar

This problem is saying that your controller expects 1 parameter and you are not passing it, so your route definition and controller are good. If you are doing something like this:

<a href="{{route('documentmodal_store',$list->pg_id)}}"></a>

Make sure that $list->pg_id is not null.

1 like
manelgavalda's avatar

Show us your store controller method, and your view to see how are you calling it.

1 like
vandan's avatar
Level 13

here is my route

Route::resource('pg/profile/{id}', 'pages\ProfileController',
    ['names'=>['index'=>'profile','store'=>'image_update','create'=>'remove_image']]);

    Route::resource('pg/document', 'pages\DocumentController',
    ['names'=>['store'=>'documentmodal_store','destroy'=>'document_delete']]);

when my document delete then redirect profile route so how to fix it

vandan's avatar
Level 13

profile index controller

public function index($id)
    {
        $view = Pg::where('user_id','=',$id)->first();        
        $doc = Document::where('pg_id','=',$view->id)->get();               
            returnview('admin.pages.pg.viewprofile',compact('user','managment','owner','country','countries','doc','view','city','state'));   
    }

here is my store method

public function destroy($id)
    {
        $doc = Pg::where('id',$id)->first();    
        $document = Document::where('pg_id',$doc->id)->first();    
        $doc_path = public_path().'/PG/Doc/'.$id.'/'.$doc->multiple_doc;  // Value is not URL but directory file path
        if(File::exists($doc_path)) {
                File::delete($doc_path);
        }
        $document->delete();
        notify()->success('Profile Document Remove Successfully !');
        return back();
    }
manelgavalda's avatar

You are showing the destroy method not the store method. And also show you blade to see how are you calling this route.

manelgavalda's avatar

I want to see the storemethod for your ProfileController, and also the html where you are calling the documentmodal_store route.

1 like
vandan's avatar
Level 13

@manelgavalda

document store method

public function store(Request $request,$id)
    {
        if(request()->has('multiple_doc'))
        {
                $files = Input::file('multiple_doc');
                $picName = str_random(30).'.'.$files->getClientOriginalExtension(); //Insert path in database
                $files->move(public_path().'/PG/Doc/'.$id.'/',$picName);       //Insert image in folder
        }

        $doc = new Document(array(
            'pg_id'=>$request->get('pg_id'),
            'doc_type'=>$request->get('doc_type'),
            'doc_name'=>$request->get('doc_name'),
            'doc_number'=>$request->get('doc_number'),
            'multiple_doc'=>$picName
        ));
        $doc->save();

        notify()->success('PG Document Successfully Added !');
        return \Redirect::route('profile',['user_id'=>$id]);
    }   

blade file

<form method="POST" action="{{route('documentmodal_store',['id'=>$view->user_id])}}" enctype="multipart/form-data">
</form>
vandan's avatar
Level 13

here is profile store

public function store($id)
    {
        if(request()->has('pgimage'))
        {
                $files = Input::file('pgimage');
                $picName = str_random(30).'.'.$files->getClientOriginalExtension(); //Insert path in database
                $files->move(public_path().'/PG/PGProfile/'.$id.'/',$picName);       //Insert image in folder

            \DB::table('pgs')
            ->where('user_id',$id)
                ->update([
                'pgimage'=>$picName
            ]);
        }
         notify()->success('Profile Image Updated Successfully !');
        return \Redirect::route('profile',['id'=>$id]);
}
Snapey's avatar

You don't need to specify the parameter on the resource route;

Route::resource('pg/profile/{id}', 'pages\ProfileController',
    ['names'=>['index'=>'profile','store'=>'image_update','create'=>'remove_image']]);

should be

Route::resource('pg/profile', 'pages\ProfileController',
    ['names'=>['index'=>'profile','store'=>'image_update','create'=>'remove_image']]);
1 like
vandan's avatar
Level 13

@snapey but my profile page data id wise page open so how to fix without id?

Snapey's avatar

Change it as suggested. Then run php artisan route:list

You will see that the parameter is expected in the route although you have not mentioned it.

1 like
Snapey's avatar

did you run route:list ?

You will see from the route list that the parameter is expected to be called profile

but in the view, you are passing id and not profile

{{route('documentmodal_store',['id'=>$view->user_id])}}

You should pass the parameter matching what is expected by the route;

{{route('documentmodal_store',['profile'=>$view->user_id])}}
1 like
vandan's avatar
Level 13

@snapey i remove $id in routes and check route list its proper profile in no $id

see

Route::resource('pg/profile', 'pages\ProfileController',['names'=>['show'=>'profile','store'=>'image_update',
        'create'=>'remove_image']]);    

profile store controller

public function store($id)
    {
        if(request()->has('pgimage'))
        {
             $files = Input::file('pgimage');
                $picName = str_random(30).'.'.$files->getClientOriginalExtension(); //Insert path in database
                $files->move(public_path().'/PG/PGProfile/'.$id.'/',$picName);       //Insert image in folder

                \DB::table('pgs')
             ->where('user_id',$id)
                ->update([
                'pgimage'=>$picName
                ]);
        }
        notify()->success('Profile Image Updated Successfully !');
        return \Redirect::route('profile');
        // return back();
    }

when i store profile picture see error Too few arguments to function App\Http\Controllers\pages\ProfileController::store(), 0 passed and exactly 1 expected

my url like http://127.0.0.1:8000/pg/profile?2

so how to fix it @snapey

Snapey's avatar

where is the view code where you call the store method on profile?

Snapey's avatar

oh, and never do this

<a href="{{route('document_delete',$list->pg_id)}}"></a>

You will have things deleted by a search bot crawling your site. Only ever delete with a POST route.

1 like
vandan's avatar
Level 13

@snapey

profile store

<form method="post" action="{{route('image_update',$view->user_id)}}" enctype="multipart/form-data">    
</form>
Snapey's avatar
Snapey
Best Answer
Level 122

Assuming your route looks like this

Route::resource('pg/profile', 'pages\ProfileController',
    ['names'=>['index'=>'profile','store'=>'image_update','create'=>'remove_image']]);

then your image_update is using the store method, used for creating a new resource. It is not expecting any parameter to be passed, so you cannot do this

public function store($id)

because store method does not use any parameter.

You should keep referring to the route:list to see what your routes expect.

1 like
vandan's avatar
Level 13

@snapey

pg/profile | image_update | App\Http\Controllers\pages\ProfileController@store

without $id how to store profile image?

vandan's avatar
Level 13

hii @manelgavalda @snapey

i found some other way to solution like i pass hidden value of id because store method can not pass parameter so

here is blade file

<form method="post" action="{{route('image_update',['id' => $view->user_id])}}" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" value="{{$view->user_id}}" name="user_id">
</form>

and store method like

public function store(Request $request)
    {
        $id = $request->get('user_id');
        if(request()->has('pgimage'))
        {
                $files = Input::file('pgimage');
                $picName = str_random(30).'.'.$files->getClientOriginalExtension(); //Insert path in database
                $files->move(public_path().'/PG/PGProfile/'.$id.'/',$picName);       //Insert image in folder

            \DB::table('pgs')
                ->where('user_id',$id)
                ->update([
                'pgimage'=>$picName
                ]);
        }
        notify()->success('Profile Image Updated Successfully !');        
        return back();
    }

its working properly @snapey @manelgavalda for your time & help

Snapey's avatar

But remember, you have to check the ID being passed.

If the profile picture belongs to the current user then use Auth::id() rather than relying on a field passed in a form.

NOTHING from the client should be trusted. I could easily come to your site and upload 'my' profile image but change the id to that of another user.

And don't forget about the delete route. NEVER use GET for a delete operation.

1 like
vandan's avatar
Level 13

@snapey thank you sir for kind of information its really help me i changed i use auth id and post route for delete method

Please or to participate in this conversation.