Ad

Controller Action Is Not Available

- 1 answer

I am not familiar with laravel but from what I red I made this: My controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ChatController extends Controller
{
    public function index(Request $request)
    {
        var_dump(123123);die;
        if (!Auth::check()) {
            return redirect('/');
        }

        return 1;
    }
}

Now I am trying to request it like domain.com/open-chat. And my web.php configuration about it is:

Route::get('/open-chat', '[email protected]');

But I am getting redirected to the home page. I`ve checked the middleware controllers if some of it redirects me but no. The other controllers ( which were already made when I came ) works fine. What am I missing ?

EDIT web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/clear-cache', function() {
    Artisan::call('cache:clear');
    return "Cache is cleared";
});
Route::get('/config-cache', function() {
    Artisan::call('config:cache');
    return "Config is cleared";
});

Route::get('/view', function() {
    Artisan::call('view:clear');
    return "View is cleared";
});

/* Route::get('/', function () {
    return view('welcome');
}); */

Route::group(['prefix' => 'siteadmin', 'namespace' => 'Admin'], function () {

    Route::get('/', 'Auth\[email protected]');
    Route::post('login', 'Auth\[email protected]')->name('admin.login');
    Route::post('logout', 'Auth\[email protected]')->name('admin.logout');
});

Route::group(['prefix'=>'siteadmin', 'namespace' => 'Admin','middleware' => 'auth'], function () {  
    Route::get('/dashboard', '[email protected]')->name('dashboard.index');
    Route::get('/edit-profile', '[email protected]');
    Route::post('/updateprofile', '[email protected]');

    /**
        Routes for site settings
    **/
    Route::get('/site-settings', '[email protected]')->name('sitesettings.index');
    Route::post('/site-settings/store', '[email protected]')->name('sitesettings.save');


    Route::get('/subject-categories', '[email protected]')->name('subject-categories.index');
    Route::get('/subject-categories/create', '[email protected]')->name('subject-categories.create');
    Route::post('/subject-categories/store', '[email protected]')->name('subject-categories.store');
    Route::get('/subject-categories/edit/{id}', '[email protected]')->name('subject-categories.edit');
    Route::post('/subject-categories/update/{id}', '[email protected]')->name('subject-categories.update');
    Route::get('/subject-categories/drop/{id}', '[email protected]')->name('subject-categories.drop');
    Route::post('/subject-categories/delete-image/{id}', '[email protected]');


    /**
        Routes for teachers users
    **/
    Route::get('/users/teachers', ['middleware'=>'auth','uses'=>'[email protected]'])->name('teachers.index');
    Route::get('/users/teachers/create', ['middleware'=>'auth','uses'=>'[email protected]'])->name('teachers.create');
    Route::post('/users/teachers/save', ['middleware'=>'auth','uses'=>'[email protected]'])->name('teachers.save');
    Route::get('/users/teachers/edit/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('teachers.edit');
    Route::get('/users/teachers/show/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('teachers.show');
    Route::post('/users/teachers/update/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('teachers.update');
    Route::get('/users/teachers/delete/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::get('/users/teachers/change-status/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::post('/users/get-cities-by-country', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::get('/users/teachers/messages/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('teachers.messages');
    Route::get('/users/teachers/view-message/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('teacher.view-message');
    Route::post('/users/teachers/delete-profile-image/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);

    /**
        Routes for driver users
    **/
    Route::get('/users/students', ['middleware'=>'auth','uses'=>'[email protected]'])->name('students.index');
    Route::get('/users/students/create', ['middleware'=>'auth','uses'=>'[email protected]'])->name('students.create');
    Route::post('/users/students/save', ['middleware'=>'auth','uses'=>'[email protected]'])->name('students.save');
    Route::get('/users/students/edit/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('students.edit');
    Route::get('/users/students/show/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('students.show');
    Route::post('/users/students/update/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('students.update');
    Route::get('/users/students/delete/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::get('/users/students/change-status/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);

    /**
        Routes for countries
    **/
    Route::get('/countries', ['middleware'=>'auth','uses'=>'[email protected]'])->name('countries.index');
    Route::get('/countries/create', ['middleware'=>'auth','uses'=>'[email protected]'])->name('countries.create');
    Route::post('/countries/save', ['middleware'=>'auth','uses'=>'[email protected]'])->name('countries.save');
    Route::get('/countries/edit/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('countries.edit');
    Route::get('/countries/show/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('countries.show');
    Route::post('/countries/update/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('countries.update');
    Route::get('/countries/delete/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::get('/countries/change-status/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::post('/countries/delete-image/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);

    /**
        Routes for cities
    **/
    Route::get('/cities', ['middleware'=>'auth','uses'=>'[email protected]'])->name('cities.index');
    Route::get('/cities/create', ['middleware'=>'auth','uses'=>'[email protected]'])->name('cities.create');
    Route::post('/cities/save', ['middleware'=>'auth','uses'=>'[email protected]'])->name('cities.save');
    Route::get('/cities/edit/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('cities.edit');
    Route::get('/cities/show/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('cities.show');
    Route::post('/cities/update/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('cities.update');
    Route::get('/cities/delete/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::get('/cities/change-status/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::post('/cities/delete-image/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);

    /**
        Routes for subjects
    **/
    Route::get('/subjects', ['middleware'=>'auth','uses'=>'[email protected]'])->name('subjects.index');
    Route::get('/subjects/create', ['middleware'=>'auth','uses'=>'[email protected]'])->name('subjects.create');
    Route::post('/subjects/save', ['middleware'=>'auth','uses'=>'[email protected]'])->name('subjects.save');
    Route::get('/subjects/edit/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('subjects.edit');
    Route::get('/subjects/show/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('subjects.show');
    Route::post('/subjects/update/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('subjects.update');
    Route::get('/subjects/delete/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::get('/subjects/change-status/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);

    /**
        Routes for classes
    **/
    Route::get('/classes', ['middleware'=>'auth','uses'=>'[email protected]'])->name('classes.index');
    Route::get('/classes/create', ['middleware'=>'auth','uses'=>'[email protected]'])->name('classes.create');
    Route::post('/classes/save', ['middleware'=>'auth','uses'=>'[email protected]'])->name('classes.save');
    Route::get('/classes/edit/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('classes.edit');
    Route::get('/classes/show/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('classes.show');
    Route::post('/classes/update/{id}', ['middleware'=>'auth','uses'=>'[email protected]'])->name('classes.update');
    Route::get('/classes/delete/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::get('/classes/change-status/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::post('/classes/get-subjects-by-category', ['middleware'=>'auth','uses'=>'[email protected]']);

    /**
        Routes for sliders
    **/

    Route::get('/sliders', '[email protected]')->name('sliders.index');
    Route::get('/sliders/create', '[email protected]')->name('sliders.create');
    Route::post('/sliders/store', '[email protected]')->name('sliders.save');
    Route::get('/sliders/edit/{id}', '[email protected]')->name('sliders.edit');
    Route::post('/sliders/update/{id}', '[email protected]')->name('sliders.update');
    Route::get('/sliders/delete/{id}', '[email protected]')->name('sliders.delete');
    Route::get('/sliders/change-status/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::post('/sliders/delete-image/{id}', '[email protected]');


    /**
        Routes for teacher classes
    **/

    Route::get('/teacher-classes', '[email protected]')->name('teacher-classes.index');
    Route::get('/teacher-classes/create', '[email protected]')->name('teacher-classes.create');
    Route::post('/teacher-classes/store', '[email protected]')->name('teacher-classes.save');
    Route::get('/teacher-classes/edit/{id}', '[email protected]')->name('teacher-classes.edit');
    Route::post('/teacher-classes/update/{id}', '[email protected]')->name('teacher-classes.update');
    Route::get('/teacher-classes/delete/{id}', '[email protected]')->name('teacher-classes.delete');
    Route::post('/teacher-classes/get-subjects-by-category', '[email protected]');
    Route::post('/teacher-classes/get-classes-by-category-and-subject', '[email protected]');

    /**
        Routes for orders
    **/

    Route::get('/orders', '[email protected]')->name('orders.index');
    Route::get('/orders/show/{id}', '[email protected]')->name('orders.show');
    Route::get('/orders/export-orders', '[email protected]')->name('orders.export-orders');

    /**
        Routes for bookings
    **/

    Route::get('/bookings', '[email protected]')->name('bookings.index');
    Route::get('/bookings/teacher-bookings/{teacher_id}', '[email protected]')->name('bookings.bookings');
    Route::get('/bookings/show/{id}', '[email protected]')->name('bookings.show');
    Route::get('/bookings/export-teacher-bookings/{teacher_id}', '[email protected]')->name('bookings.export-teacher-bookings');

    /**
        Routes for bookings
    **/

    Route::get('/messages', '[email protected]')->name('messages.index');
    Route::get('/messages/show/{id}', '[email protected]')->name('messages.show');

    /**
        Routes for reviews
    **/

    Route::get('/reviews', '[email protected]')->name('reviews.index');
    Route::get('/reviews/show/{id}', '[email protected]')->name('reviews.show');


    /**
        Routes for blogs
    **/

    Route::get('/blogs', '[email protected]')->name('blogs.index');
    Route::get('/blogs/create', '[email protected]')->name('blogs.create');
    Route::post('/blogs/store', '[email protected]')->name('blogs.save');
    Route::get('/blogs/edit/{id}', '[email protected]')->name('blogs.edit');
    Route::post('/blogs/update/{id}', '[email protected]')->name('blogs.update');
    Route::get('/blogs/delete/{id}', '[email protected]')->name('blogs.delete');
    Route::get('/blogs/change-status/{id}', ['middleware'=>'auth','uses'=>'[email protected]']);
    Route::post('/blogs/delete-image/{id}', '[email protected]');

});

Auth::routes();

Route::get('{locale?}', '[email protected]');
Route::get('/en', '[email protected]');
Route::get('/open-chat', '[email protected]');
Route::get('/ar', '[email protected]');
Route::get('/home', '[email protected]')->name('home');

Route::post('/get-cities-by-country', '[email protected]');
Route::post('/get-subjects-by-category', '[email protected]');

Route::post('/register', '[email protected]');
Route::post('/login', '[email protected]');
Route::post('/forgot-password', '[email protected]');
Route::get('/{locale?}/reset-password/{token}', '[email protected]');
Route::post('/{locale?}/resetpassword', '[email protected]')->name('reset-pass');

Route::get('/{locale?}/classes/search', '[email protected]')->name('search');
Route::get('/{locale?}/classes/all-cities', '[email protected]');
Route::get('/{locale?}/classes/{type}/{id}', '[email protected]');

Route::get('/{locale?}/view-class/{id}', '[email protected]')->name('view-class');
Route::get('/{locale?}/finish-class/{id}', '[email protected]')->name('finish-class');

Route::post('/create-booking', '[email protected]');
Route::post('/{locale?}/submit-review', '[email protected]');

Route::get('/{locale?}/blogs', '[email protected]')->name('blogs');
Route::get('/{locale?}/blogs/{slug}', '[email protected]')->name('blogs.detail');


Route::get('/paypal/checkout/{order}/completed', [
    'name' => 'PayPal Express Checkout',
    'as' => 'paypal.checkout.completed',
    'uses' => 'User\[email protected]',
]);

Route::get('/paypal/checkout/{order}/cancelled', [
    'name' => 'PayPal Express Checkout',
    'as' => 'paypal.checkout.cancelled',
    'uses' => 'User\[email protected]',
]);

Route::post('/webhook/paypal/{order?}/{env?}', [
    'name' => 'PayPal Express IPN',
    'as' => 'webhook.paypal.ipn',
    'uses' => 'User\[email protected]hook',
]);

/**
    User dashboard routes start
**/
Route::group(['prefix'=>'{locale?}/user', 'namespace' => 'User','middleware' => 'auth'], function () {
    Route::get('/dashboard', '[email protected]')->name('user.dashboard');
    Route::get('/edit-profile', ['uses'=>'[email protected]'])->name('user.edit-profile');
    Route::post('/update-profile/{id}', ['uses'=>'[email protected]'])->name('user.update-profile');
    Route::post('/update-image/{id}', ['uses'=>'[email protected]'])->name('user.update-image');
    Route::get('/change-password', ['uses'=>'[email protected]'])->name('user.change-password');
    Route::post('/update-password', ['uses'=>'[email protected]'])->name('user.update-password');

    Route::get('/my-classes', ['uses'=>'[email protected]'])->name('user.my-classes');
    Route::get('/my-classes/add-new-class', ['uses'=>'[email protected]'])->name('user.add-new-class');
    Route::post('/my-classes/save-class', ['uses'=>'[email protected]'])->name('user.save-class');
    Route::get('/my-classes/edit-class/{id}', ['uses'=>'[email protected]'])->name('user.edit-class');
    Route::post('/my-classes/update-class/{id}', ['uses'=>'[email protected]'])->name('user.update-class');
    Route::get('/my-classes/delete-class/{id}', ['uses'=>'[email protected]']);


    Route::post('/get-subjects-by-category', ['uses'=>'[email protected]']);
    Route::post('/get-classes-by-category-and-subject', ['uses'=>'[email protected]']);

    Route::get('/my-bookings', ['uses'=>'[email protected]'])->name('user.my-bookings');
    Route::get('/my-bookings/view-booking-details/{id}', ['uses'=>'[email protected]'])->name('user.view-booking-details');
    Route::get('/my-bookings/cancel-booking/{type}/{id}', ['uses'=>'[email protected]']);
    Route::get('/my-bookings/accept-booking/{id}', ['uses'=>'[email protected]']);
    Route::post('/make-a-payment', ['uses'=>'[email protected]'])->name('user.make-payment');

    Route::get('/my-orders', ['uses'=>'[email protected]'])->name('user.my-orders');
    Route::get('/messages', ['uses'=>'[email protected]'])->name('user.messages');
    Route::get('/messages/view-messages/{thread_id}', ['uses'=>'[email protected]'])->name('user.view-messages');
    Route::post('/messages/send-message', ['uses'=>'[email protected]']);

    Route::get('/reviews', ['uses'=>'[email protected]'])->name('user.reviews');

});

Extended Controller.php:

<?php

namespace App\Http\Controllers;

    use Illuminate\Foundation\Bus\DispatchesJobs;
    use Illuminate\Routing\Controller as BaseController;
    use Illuminate\Foundation\Validation\ValidatesRequests;
    use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

    class Controller extends BaseController
    {
        use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    }
Ad

Answer

This rule Route::get('{locale?}', '[email protected]'); is catching all routes because it's always true. so Laravel follows this route.

the problem is not about Route::get('/open-chat', '[email protected]'); if you put any route after that one, it won't work.

we usually use this to catch all request to forward somewhere like Vuejs router or show 404 message.

Route::any('{catchall}', '[email protected]')->where('catchall', '.*');

and these are pretty same. if you put Route::get('{locale?}', '[email protected]'); at the end of your router file, everything should work fine.

Ad
source: stackoverflow.com
Ad