I have following Controller Action Method.
namespace App\Http\Controllers\API\SportsType;
class SportsTypeApiController extends \App\Http\Controllers\Controller
{
public function apiSportsTypes() {
return 1;
}
}
Here is the route
Route::group(['prefix' => 'api/v1'], function () {
Route::get('/apiSportsTypes', 'API\SportsType\SportsTypeApiController#apiSportsTypes');
});
It gives 404 error. Am I missing something? Please let me know if you need more details.
It was happening because the routes were using cache. Due to that new routes were not even appearing in command prompt even if I was typing below command.
php artisan route:list
Then I had to remove the route cache by using the below command
php artisan route:clear
and now everything is working fine.
Related
I am completely new to laravel, so I think my question is a bit ridiculous.
I tried to create a route in the routes/web.php
Route::get('/example', function () {
Return ('hello');
)};
But when I try to see the example page, I receive 404.
I use php artisan serve to load the local host.
I couldn't find a solution relatable to my situation. Still no luck.
Windows version 8.1
Laravel version 8
Also I can't edit
Route::get('/', function () {
Return view ('welcome');
});
The changes won't apply
Thank you
You can type php artisan route:list to see if the route saved or not, if not you can write :
php artisan optimize:clear
Your syntax is not correct.
Route::get('/example', function () {
Return view('hello');
});
Make your hello.blade.php file add your html code that is your view file.run command php artisan route:clear.
you must use:
php artisan:serve
then
your_app_url/example
and edit web.php -- you have syntax error in web.php
Route::get('/example', function () {
return 'hello';
});
I am creating a simple website in Laravel while running a web site ran into the problem with 404 NOT FOUND Laravel 8. index page working when I click on about us and contact us page getting error of 404 NOT FOUND I don't know why is that. what I tried so far I attached below.
Folder structure
Controller
class SmsController extends Controller
{
public function index()
{
return view('index');
}
public function aboutus()
{
return view('aboutus');
}
public function contactus()
{
return view('contactus');
}
}
Index.blade.php I made the links
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Aboutus</li>
<li>Contactus</li>
</ul>
routes
Route::get('/', 'App\Http\Controllers\SmsController#Index');
Route::get('Aboutus', 'App\Http\Controllers\SmsController#aboutus');
Route::get('Contactus', 'App\Http\Controllers\SmsController#contactus');
I think you got error here
Route::get('Aboutus', 'App\Http\Controllers\SmsController#aboutus');
Route::get('Contactus', 'App\Http\Controllers\SmsController#contactus');
instead
Route::get('/aboutus', 'App\Http\Controllers\SmsController#aboutus');
Route::get('/contactus', 'App\Http\Controllers\SmsController#contactus');
I use this command:
php artisan route:cache
then
php artisan serve
After that, copy the IP address after second command.
In laravel 8 you can try this way:
Route::get('/', [App\Http\Controllers\SmsController::class, 'index']);
Route::get('/about-us', [App\Http\Controllers\SmsController::class, 'aboutus']);
Route::get('/contact-us', [App\Http\Controllers\SmsController::class, 'contactus']);
I had to use php artisan route:cach command in terminal.
In my laravel 9 case, I added a new attribute style routes and it gave 404 error, from console writing
`php artisan route:clear`
has solved my issue.
try to write a route like this
Route::get('/aboutus', 'App\Http\Controllers\SmsController#aboutus');
Thank you guys, I have been on this for close to two days, this is what helped me
php artisan route:cache
using v9
The problem is with the route address since the Laravel route are case sensitive.
the correct form of route
Route::get('/aboutus', 'App\Http\Controllers\SmsController#aboutus');
Route::get('/contactus', 'App\Http\Controllers\SmsController#contactus')'
and also it is worth mentioning that the updated accepted way to write routes in the Laravel 8.x to-class method is
Route::get('/aboutus', [App\Http\Controllers\SmsController::class, 'aboutus']);
Route::get('/contactus', [App\Http\Controllers\SmsController::class, 'contactus']);
but the old method is still accessible on the newer version of Laravel
I'm using laravel 7.x.
since function(){return view(welcome);} will produce an error when I run php artisan route:cache, so I write this code below to replace function():
Route::get('/', 'WelcomeController#index')->name('welcome');
It run well on php artisan serve command.
But when i run directly from public folder, it produce exception MethodNotAllowedHttpException. I couldn't find why it happened, could you help me why it happened?
exception message:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: HEAD.
https://localhost/laravel-tester/public/
WelcomeController Method
public function index(){
return view('welcome');
}
::get registers the route for methods GET and HEAD by default. You are trying to access it with a GET request (as you should) but it does not return it. Possibly there is something wrong with your Router class, so please check your Routing\Router.php class against the method in the comment below.
https://stackoverflow.com/a/22119028/10187949
I have just created one of about view in view/about.blade.php, and I am accessing this from localhost/myproject/public/about, but it's not working.
However, localhost/myprojects/public/ is working fine; about view has been created on same parameters as welcome by default in Laravel.
Firstly the information is not sufficient to say anything.Please provide your route.Also its important how you are running your project ,is it via Xampp(or Lampp whatever is there) or "php artisan serve"
but looking from your working directory "localhost/myprojects/public" I guess its not by the command . Try localhost/myprojects/public/about.blade.php or run it by php artisan serve and try route localhost:8000/about
Have you added particular routing to web.php file?
Route::get('about', function () {
return view('about');
});
https://laravel.com/docs/5.7/routing
Which error are you getting?
404 - Not found
Route::get('/about', function () {
return view('about');
});
Check routes
php artisan route:list
Laravel is a MVC Framework, Which means You Have a Controller which procede some logic when some request come in and interact with the model if need, after that the controller return some view.
And because you whan to acccess your view file, you must past through controller, and that controller will render the view. Because the views folder is not in the \public dicretory as subdirectory you can't access to It with url like localhost/myproject/public/about even if you get access to it, you will not get HTML, you'll get some plain text with Blade tags. It's a must to return view in you controller by rendering it, somewhere in the background Laravel procede all Blade Tag and return HTML that correspond to that tags.
What I can suggest you Is to create some route in your route file like this
Route::get('/about', function(Request $request){
// Automatically Laravel will look this file in the view directory
return view('about');
});
Or you can go with the controller like procedure by creating some controller, go in your terminal and execute
php artisan make:controller AboutController
this will generate a file name AboutController.php in app\Http\Controllers diretory within witch you will found
namespace App\Http\Controllers;
class HomeController extends Controller
{
}
after that add
public function index()
{
return View::make('about');
}
Don't forget to include use the Illuminale\Supports\Facades\View on top of your file
And one more important thing which left is to configure the Route, for that go in routes directory in the web.php file add
Route::get('/about', 'AboutController#index')->name('about');
I am using laravel 5.4 and trying to get index page, i am using following routes
Route::get('/',
['as' => 'home_page',
'uses' => 'Controller#index']);
and index function in controller looks like this:
public function index()
{
return view('index');
}
But when I visit mydomain.com, I get a different view than index.blade.php.
and it is fine when I use mydomain.com/? or on my local server.
I have searched everywhere in my code and in a google, but didn't found anything, any help?
ie: let me know if any further information required.
First make sure you are calling the right controller, and this dont have a specific middleware blocking the acess to your index method and index.blade.php is inside view folder.
If all of this is fine try this code on your rotes file:
Route::get('', function () {
return view('index');
})
Try this.
First use the make:controller Artisan command to create a controller file. let's say it is homeController.
php artisan make:controller homeController
Then in the homeController file write your code to get the view.
<?php
namespace App\Http\Controllers;
class homeController extends Controller
{
public function index()
{
return view('index');
}
}
Then define a route to this controller.
Route::get('/', 'homeController#index');
For more information please refer https://laravel.com/docs/5.5/controllers
There was a cached view saved on my server, I used
php artisan cache:clear and it got fixed. Thank you everyone for the support.