0

situation

using PHP 8 Laravel 9

Now I have just deployed in production environment. When I come my URL which is already simbolick, toppage(welcome.blade.php) appeared. I am putting link to contact.create.blade.php. However I come here, the error I show appeares.

In local, I can go to the link, but in production, the error says not defined maybe to mistake routes. Now I can go to the link in local.

Can you tell me this problem and how to solve it.

error messages

error

Route [contact.create] not defined.

welcome.blade.php

            <div>
                {{-- ボタン設定 --}}
                <a href="{{route('contact.create')}}">
                <x-primary-button class="next-button  text-center">お問い合わせ</x-primary-button>
                </a>
                <a href="{{route('register')}}">
                    <x-primary-button class="next-button  text-center">ご登録</x-primary-button>
                </a>
            </div>

web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PostController;
use App\Http\Controllers\CommentController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\SearchController;
use App\Http\Controllers\NiceController;
use App\Http\Controllers\StripeController;
use App\Http\Controllers\FollowController;
use App\Models\Role;

Route::get('/', function () {
    return view('welcome');
})->name('top');

~~~~~~~~~~

// contact
Route::get('contact/create',[ContactController::class,'create'])->name('contact.create');
Route::post('contact/store',[ContactController::class,'store'])->name('contact.store');

ContactController.php

<?php

namespace App\Http\Controllers;

use App\Models\Contact;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Mail\ContactForm;

class ContactController extends Controller
{
    public function create()
    {
        return view('contact.create');
    }
    public function store(Request $request)
    {
        $inputs = request()->validate([
            'title' => 'required|max:255',
            'email' => 'required|email|max:255',
            'body' => 'required|max:1000',
        ]);
        Contact::create($inputs);
        Mail::to(config('mail.admin'))->send(new ContactForm($inputs));
        Mail::to($inputs['email'])->send(new ContactForm($inputs));
        return back()->with('message','submitted your email!');
    }
}

I don't know anything because I can go to link in local but this error appeares in production.

I tried php artisan optimize:clear, but nothing changed at all.

  • Try running `php artisan route:clear` in your production environment. And then, reload your application and try again. – steven7mwesigwa Dec 02 '22 at 04:52
  • In addition, if the above command doesn't work for you, try running `php artisan cache:clear` in your production environment. And then, reload your application and try again. – steven7mwesigwa Dec 02 '22 at 04:55
  • Does this answer your question? [Laravel says "Route not defined"](https://stackoverflow.com/questions/28714675/laravel-says-route-not-defined) – steven7mwesigwa Dec 02 '22 at 05:07
  • [Laravel 8 Route not defined even route is defined](https://stackoverflow.com/questions/69432988/laravel-8-route-not-defined-even-route-is-defined) – steven7mwesigwa Dec 02 '22 at 05:07
  • Thank you for your comments. I tried`php artisan route:clear`,`php artisan cache:clear` or the other clear commands, but nothing changed at all. – 平野絢士 Dec 02 '22 at 08:45
  • Also I check as `php artisan route:list` in production environment, but contact or the other routes do not exist. – 平野絢士 Dec 02 '22 at 08:49
  • When you say *'...the other routes do not exist.'* Which routes are you referring to? – steven7mwesigwa Dec 02 '22 at 09:01
  • Of cource contact.create.php does not exist in the list in production environment, likewise the other (for example post.create.php or show.blade.php) do not exist dispite I made them, but in local, they exist in a route-list. – 平野絢士 Dec 02 '22 at 11:04

0 Answers0