- Can confirm
ajax()is not throwing 404? (Test by doing add("ajax() called");first line of your method) - If confirmed, can you do a
php artisan route:list?
Laravel 8 Routes broken
I have upgraded to laravel 8 and now my post ajax routes return a 404?
Route::post('/{phone}', 'DealsController@ajax');
Route::get('/{phone}', 'DealsController@show');
I have also tried:
Route::post('/{phone}', [DealsController::class, 'ajax']);
but still when ajax is called the route returns a 404 csrf token is sent in the payload along with the model ID and other params (the query in the controller works and returns json data)
Hmm nothing from the dd but have just noticed event though the get route works it too returns a 404 the route shows in route:list
very much a work in progress but you can see it in action here: https://shopmobilephones.co.uk/iphone-11 click on one of the options in the left hand filters like no up front cost to trigger an ajax call
Your routes are overwriting each other, /{phone} is a very generic route, make it more unique.
did you import the controller to the route file?
yep controllers imported at the top of web.php
I should be able to define multiple to the same uri get, post, put, patch, delete etc should determine which method is hit?
Does it both happen on development and production?
No it doesn't happen on dev interestingly the autocomplete also doesn't work in production but does in dev
Try this on production
php artisan optimize:clear
no joy im afraid :(
Any folders in the public directory with the same name as the url?
No none
Which controller does this link route to? https://shopmobilephones.co.uk/iphone-11
DealsController
Can show your web.php?
use App\Http\Controllers\DealsController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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!
|
*/
// front end routes:
Route::get('/', 'IndexController@index');
//Networks
Route::get('/networks/{slug}','NetworksController@show');
// buy
Route::get('/buy/{deal}','DealController@buy');
// Search
Route::get('/search','SearchController@search');
// deal
Route::get('/deal/{deal}','DealController@show');
Route::post('/{phone}', [DealsController::class, 'ajax']);
//Route::post('/{device}', 'DealsController@ajax');
Route::get('/{phone}', 'DealsController@show');
Route::get('/home', 'HomeController@index')->name('home');
// admin
//Route::get('/test',function(){
// $feeds = (new App\Http\Controllers\DatafeedController)->parseXml('buymobiles.xml');
//
//});
Route::get('/home', 'HomeController@index')->name('home');
/** Admin Routes */
//Retailers
Route::get('/admin/retailers','RetailerController@index')->middleware('auth');
Route::get('/admin/retailers/create','RetailerController@create')->middleware('auth');
Route::post('/admin/retailers/create','RetailerController@store')->middleware('auth');
Route::get('/admin/retailers/{retailer}','RetailerController@show')->middleware('auth');
Route::post('/admin/retailers/{retailer}','RetailerController@update')->middleware('auth');
Route::post('/admin/retailers/destroy/{retailer}','RetailerController@destroy')->middleware('auth');
// Retailers -> Datafeeds
Route::get('/admin/retailers/{retailer}/datafeeds','DatafeedController@index')->middleware('auth');
Route::get('/admin/retailers/{retailer}/datafeeds/create','DatafeedController@create')->middleware('auth');
Route::post('/admin/retailers/{retailer}/datafeeds/create','DatafeedController@store')->middleware('auth');
Route::get('/admin/retailers/{retailer}/datafeeds/{datafeed}','DatafeedController@show')->middleware('auth');
Route::post('/admin/retailers/{retailer}/datafeeds/{datafeed}','DatafeedController@update')->middleware('auth');
Route::get('/admin/retailers/{retailer}/datafeeds/{datafeed}/destroy','DatafeedController@destroy')->middleware('auth');
// Retailers -> Datafeeds -> Schedules
Route::get('/admin/retailers/{retailer}/datafeeds/{datafeed}/schedule','ScheduleController@index')->middleware('auth');
Route::get('/admin/retailers/{retailer}/datafeeds/{datafeed}/schedule/create','ScheduleController@store')->middleware('auth');
//Networks
Route::get('/admin/networks','NetworkController@index')->middleware('auth');
Route::get('/admin/networks/create','NetworkController@create')->middleware('auth');
Route::post('/admin/networks/create','NetworkController@store')->middleware('auth');
Route::get('/admin/networks/{network}','NetworkController@show')->middleware('auth');
Route::post('/admin/networks/{network}','NetworkController@update')->middleware('auth');
Route::post('/admin/networks/destroy/{network}','NetworkController@destroy')->middleware('auth');
//Products
Route::get('/admin/products','ProductController@index')->middleware('auth');
Route::get('/admin/products/create','ProductController@create')->middleware('auth');
Route::post('/admin/products/create','ProductController@store')->middleware('auth');
Route::get('/admin/products/{product}','ProductController@show')->middleware('auth');
Route::post('/admin/products/{product}','ProductController@update')->middleware('auth');
Route::post('/admin/products/destroy/{product}','ProductController@destroy')->middleware('auth');
//Product -> Versions
Route::get('/admin/products/{product}/version','ProductVersionController@index')->middleware('auth');
Route::get('/admin/products/{product}/version/create','ProductVersionController@create')->middleware('auth');
Route::post('/admin/products/{product}/version/create','ProductVersionController@store')->middleware('auth');
Route::get('/admin/products/{product}/version/{productVersion}','ProductVersionController@show')->middleware('auth');
Route::post('/admin/products/{product}/version/{productVersion}','ProductVersionController@update')->middleware('auth');
Route::post('/admin/products/{product}/version/destroy/{productVersion}','ProductVersionController@destroy')->middleware('auth');
//Product -> Versions -> Editions
Route::get('/admin/products/{product}/{productVersion}/edition','ProductEditionController@index')->middleware('auth');
Route::get('/admin/products/{product}/{productVersion}/edition/create','ProductEditionController@create')->middleware('auth');
Route::post('/admin/products/{product}/{productVersion}/edition/create','ProductEditionController@store')->middleware('auth');
Route::get('/admin/products/{product}/{productVersion}/edition/{productEdition}','ProductEditionController@show')->middleware('auth');
Route::post('/admin/products/{product}/{productVersion}/edition/{productEdition}','ProductEditionController@update')->middleware('auth');
Route::post('/admin/products/{product}/{productVersion}/edition/destroy/{productEdition}','ProductEditionController@destroy')->middleware('auth');
// Product -> versions -> editions -> identifiers
Route::get('/admin/products/{product}/{productVersion}/edition/{productEdition}/identifier','ProductIdentifierController@index')->middleware('auth');
Route::get('/admin/products/{product}/{productVersion}/edition/{productEdition}/identifier/store','ProductIdentifierController@store')->middleware('auth');
Route::post('/admin/products/{product}/{productVersion}/edition/{productEdition}/identifier/{identifier}','ProductIdentifierController@update')->middleware('auth');
Route::post('/admin/products/{product}/{productVersion}/edition/{productEdition}/identifier/{identifier}/destroy','ProductIdentifierController@destroy')->middleware('auth');
// Product -> versions -> editions -> features
Route::get('/admin/products/{product}/{productVersion}/edition/{productEdition}/features','ProductFeatureController@index')->middleware('auth');
Route::post('/admin/products/{product}/{productVersion}/edition/{productEdition}/features/{features}','ProductFeatureController@update')->middleware('auth');
Route::post('/admin/products/{product}/{productVersion}/edition/{productEdition}/features/{features}/destroy','ProductFeatureController@destroy')->middleware('auth');
// Product -> versions -> editions -> specifications
Route::get('/admin/products/{product}/{productVersion}/edition/{productEdition}/specifications','ProductSpecificationController@index')->middleware('auth');
Route::post('/admin/products/{product}/{productVersion}/edition/{productEdition}/specifications/{specifications}','ProductSpecificationController@update')->middleware('auth');
Route::post('/admin/products/{product}/{productVersion}/edition/{productEdition}/specifications/{specifications}/destroy','ProductSpecificationController@destroy')->middleware('auth');
//Tariff Group]
Route::get('/admin/tariff-group','TariffGroupController@index')->middleware('auth');
Route::get('/admin/tariff-group/create','TariffGroupController@create')->middleware('auth');
Route::post('/admin/tariff-group/create','TariffGroupController@store')->middleware('auth');
Route::get('/admin/tariff-group/{tariffGroup}','TariffGroupController@show')->middleware('auth');
Route::post('/admin/tariff-group/{tariffGroup}','TariffGroupController@update')->middleware('auth');
Route::post('/admin/tariff-group/destroy/{tariffGroup}','TariffGroupController@destroy')->middleware('auth');
//Tariff details
Route::get('/admin/tariff-group/{tariffGroup}/tariffs','TariffDetailController@index')->middleware('auth');
Route::get('/admin/tariff-group/{tariffGroup}/tariffs/{tariff}','TariffDetailController@show')->middleware('auth');
// Tariff allowances
Route::get('/admin/tariff-group/{tariffGroup}/tariffs/{tariff}/allowances','TariffAllowanceController@show')->middleware('auth');
// Sales
Route::post('/admin/sales','SalesController@store');
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
It seems like all post routes don't work the auth ones don't either - is there something Laravel 8 specific that needs importing for post routes to work?
That said all work in my local env macbook pro, production is digital ocean ubuntu 18.0.4 / forge provisioned LEMP stack
These routes
Route::post('/{phone}', 'DealsController@ajax');
Route::get('/{phone}', 'DealsController@show');
has to be in the bottom of web.php file.
Yeah I tried that
In such a situation, I always put my path on the top of all the routes.
Do you have some middleware? And what php version are you running on the server? Did you remember to run composer install
I am thinking some error occurs and you redirect to a some non existent url
Yep ran composer install and just installed the standard laravel ui and auth
I Bet its cloudflare proxying requests ?
nope its not lol - I am completely stumpt
It is declared two times please remove one of them
Route::get('/home', 'HomeController@index')->name('home');
Bring in the biggest gun... xdebug :)
Your web.php indicates you have made 'unofficial' modifications such as re-implementing the support of 'DealsController@show'. I can only speculate where the issue is.
still no joy im afraid
Given that it worked in dev but not in production, how are you deploying?
via git with forge running composer update after each pull
Composer update? Never update on production. Only install
Please or to participate in this conversation.