I am very new to laravel and I simply don't get how to route properly, am completely lost. The problem is I can only route a view to localhost/public. For example I can't route a view to "localhost/public/something". Am not even sure my urls are correct. If i leave "something.php" empty nothing will show, but if i add some html it shows only the html no views. Am sure am doing it all wrong. So how does one route a view to a page other than "public/".
The routing for index is
Route::get('/', function(){
return View::make('welcome');
});
works okay.
Now how can I achieve the same if do
Route::get('something', function(){
return View::make('welcome');
});
or
Route::get('/something', function(){
return View::make('welcome');
});
So i finally got it to work after so many hours. I deleted my laravel installation and did a new one and the problem is gone. Thanks.
There's nothing wrong with your code but might be for .htaccess
Please try accessing the route via following URL
http://localhost/public/index.php?/something
if it's working, you need to use the alternative .htaccess file provided on Laravel website or see if mod_rewrite is loaded on your Apache.
Related
I am newbie to laravel and i am working on a project and i have a following situation
lets assume my base url is https://example.com
Now i want to pass a slug(argument) after a base url which means https://example.com/xyz something like that, and i need to do this on multiple times in my project
This is what i'd tried but it is not working it says that route is not defined.
Route::get('{slug?}', [App\Http\Controllers\UiviewsController::class, 'method1'])->name('method1');
Route::get('/method2/{slug?}', function($slug){
return redirect()->route('method1', ['slug'=>$slug]);
});
And also how can i achieve that on which argument which particular method should be called? for example if i have several other routes similar to above one.
how can i achieve this?
Thank you in advance for your help. :)
You should use the fallback system.
Route::fallback(function () {
//
});
Laravel Route fallback official docs
also, beware:
The fallback route should always be the last route registered by your
application.
Other Option:
Also, you can define a parameter as below example
Route::any('{any}', function(){
//...
})->where('any', '.*');
Please Try php artisan route:cache in your terminal then check it again.
I have been invited to collaborate on a laravel 7 project and I have been able to set up the project locally on a windows 10 system using wamp server. While reviewing the project, I noticed the plan is to use subdomain routing. I am currently tasked with setting up the blade templates and I want to test the route but I can't get the route to work correctly even though the routes exist. This is what the routes look like
When i try viewing the page for realestate by calling the url like this realestate.localhost:8000 I get the connection error below
The route is inside routes/realestate.php folder and its using a closure
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return 'Realestate Routes';
});
What is the right way to call the route in my local enviroment on windows?
I'm not sure if your environment is different from mine, but make sure you're accessing via http:// and not https://
I just saw your Route code - it's been a long day, sorry :P
Try reading up on Subdomain routing here.
Your Route should look like this:
Route::domain('realestate.localhost')->group(function () {
Route::get('/', function () {
return 'Hello, world!'
});
// all other routes for realestate.localhost go in here
});
You need to edit your hosts and add redirect to localhost from your subdomain. see https://stackoverflow.com/a/56921347/11775360
I have a website in laravel framework and I am trying to add a simple new static page to the admin panel. I have done the following three steps:
Add a template to the views:
app/views/admin/MessageToAll.blade.php
Add the make view code in the controller.
public function MessageToAll(){
return View::make('admin.MessageToAll');
}
Added a route in app/routes.php
Route::get('/admin/MessageToAll',array('as'=>'MessageToAll','uses'=>'AdminController#MessageToAll'));
But when I go to to domain.com/admin/MessageToAll
it gives me a 404 page not found error. Does anyone know what have I missed as I think I have completed all steps for adding this view.
Just put your new route before the /admin/ route (to test it, you want to temporarily make it the very first route in routes.php). The problem is /admin/ or some other similar route executed before your new route.
Also, if you need to just execute static view, you can use something like this (works without using a controller):
Route::get('/admin/MessageToAll', function (){
return View::make('admin.MessageToAll');
});
in routes add:
Route::get('/admin/MessageToAll','yourController#yourMethod');
I am having troubles getting laravel to find a page when I route to it. My route is setup and being recognized as when I create link using URL::route('account-create') laravel will successfully parse that into '/account/create' as to where I want the link to go to. But upon clicking it I get a 404 error.
My route
Route::get('/account/create', array(
'as' => 'account-create',
'uses' => 'AccountController#getCreate'
));
My controller
class AccountController extends BaseController {
// view the create user form
public function getCreate()
{
//return View::make('account.create');
}
}
The create.blade.php is created and put inside an account folder under app/views. commenting or uncommenting makes no difference. The 404 remains.
I have also tried:
Route::get('/account/create', function()
{
return 'Hello World';
});
in my routes.php still the 404 remains
Is there some configuration I am missing?
After looking around some more I discovered I needed to enable rewrite_module on apache. Makes perfect sense really, how can laravel make clean urls if it cant rewrite the url. I knew it was going to be something simple to fix.
Thanks a lot for your replys
Does navigating to index.php/account/create work? If so, it is probably an error in your root-level .htaccess file, or in your VirtualHost settings in httpd.conf on your server. Post the contents of .htaccess from app/public.
Following this http://laravel.com/docs/quick#routing
I add this:
Route::get('users', function()
{
return 'Users!';
});
to the bottom of /app/routes.php and GET it from my browser http://localhost/users. But the returned result is users Not Found.
I've also tried a route of /users too, and this does the same.
Oh no, the route should be:
http://localhost/index.php/users
That should work.