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

joshblevins's avatar

Action CompaniesController@store not defined

I am trying to build a form using laravel. I continue to get this error... Action CompaniesController@store not defined ...

When I take out the action route on the form open I can view the page without error. Below is my code.

Routes:

Route::get('companies', 'CompaniesController@index');
Route::get('companies/create', 'CompaniesController@create');

CompaniesController

    <?php
    namespace Vanguard\Http\Controllers\Web;
use Vanguard\Http\Controllers\Controller;
use Vanguard\Companies;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use DB;

/**
 * Class CompaniesController
 * @package Vanguard\Http\Controllers
 */
class CompaniesController extends Controller
{
    public function index()
    {
        // Fetch users from database
        $companies = Companies::select('companies.*')->get();
        
        // Uncomment the following line if you want to see the info you get from the database
        // dd($users);

        // Load appropriate view for displaying the users
        // Note: compact('users') is the same as ['users' => $users] 
        return view('companies.index', compact('companies'));   
    }

    public function store(Request $request)
    {
        $this-> validate($request, [
            'company_name'=> 'required',
            'phone'=> 'required',
            'email'=> 'required'
        ]);
        
        return 123;
    }
    
    public function show(){
        //
    }

    public function create()
    {
     
  
        return view('companies.create');   
    }
    

}

create.blade.php

@extends('layouts.app')

@section('page-title', trans('app.dashboard'))
@section('page-heading', trans('app.dashboard'))

@section('breadcrumbs')
    <li class="breadcrumb-item active">
        @lang('Companies')
    </li>
@stop

@section('content')



{{ Form::open(['action' => 'CompaniesController@store']) }}
    //
{{ Form::close() }}
@stop
0 likes
8 replies
tykus's avatar
tykus
Best Answer
Level 104

Does the Form Builder know that you are using a non-conventional namespace for the route? Possibly you need:

{{ Form::open(['action' => 'Vanguard\Http\Controllers\WebCompaniesController@store']) }}
Snapey's avatar

You need to declare a route so that the action method can find the route you are talking about

eg

Route::get('companies', 'CompaniesController@index');
Route::get('companies/create', 'CompaniesController@create');
Route::post('companies','CompaniesController@store');
1 like
joshblevins's avatar

I changed my routes to look like suggested.

''' Route::get('companies', 'CompaniesController@index'); Route::get('companies/create', 'CompaniesController@create'); Route::post('companies','CompaniesController@store'); ''' Unfortunatly same error persists.

extjac's avatar
php artisan route:clear
composer dump-autolaod

and try this

<form method="POST" action="/companies">
    @csrf
    
</form>
Snapey's avatar

I wonder if 'action' is looking in the app namespace? (as @tykus was thinking)

Try

Route::post('companies','CompaniesController@store')->name('companies.store');

and then

{{ Form::open(['route' => 'companies.store']) }}

And also check with php artisan route:list to check the store method is listed

1 like
joshblevins's avatar

The first answer given worked..... I tried all of these solutions....

@Snapey is there a way to make your solution work I like the feel and look of coding in that syntax.

Also the companies.store was stored in the method list when i ran the artisan command. Which previously was not showing up. However the page still did not load.

Snapey's avatar

Well looking back, I notice that you have Controllers/Web, so my route should have been

Route::post('companies','Web\CompaniesController@store')->name('companies.store');

I'm confused though since by this then neither of these should work

Route::get('companies', 'CompaniesController@index');
Route::get('companies/create', 'CompaniesController@create');

```
joshblevins's avatar

Agree by logic no other route would work with out the Web\

That is where I got lost with the other two working without an issue.

I’m at a loss, I’m going to keep looking into the issue, because I should not need to put the Web\ in front of the controller name as the static route to the controllers folder is already defined in the namespace.

Please or to participate in this conversation.