Unable to route blade file in Laravel 4 - php

I have problem in my Laravel 4 project. I want to start using blade template but all I got is error when loading project.
I have an index.php view and this is my routes.php file:
Route::get('/', function()
{
return View::make('index');
}
And all this works like a charm. But alter I change my view file name to index.blade.php nothing works anymore.
I have tried to change my routes.php file to:
Route::get('/', function()
{
return View::make('index.blade');
}
But no luck.
What I have been missing?

Try setting up your local environment to get more detailed error messages.
http://laravel.com/docs/configuration#environment-configuration
You should be good to go with:
Route::get('/', function()
{
return View::make('index');
});
Notice the closing parenthesis and semicolon, which is the only thing that I notice missing from your code.

Related

The get in laravel doesn't find any page

I am very a beginner in Laravel
I launch my laravel project on localhost
<http://localhost/ecommerce/public/>
Route::get('/', function () {
return view('welcome');
});
this give me the welcome page
But I want to add about page but it always say "404 Not found"
and that's my code:
Route::get('/about', function () {
return view('about');
});
I made a file in views and called it "about.blade.php"
when I type to view about like this :
Route::get('/', function () {
return view('about');
});
and remove the welcome get, it works and give the about page
but when I put it in get "/about" it always doesn't work, even if I just type "string"
why it can't recognize get "/about"?
You should run the project with php artisan serve in terminal or in the server you have to change document root and remove the public in URL
the reason is the extra public in your url

How to properly define the home (/) route in Laravel?

Let's say I am defining the following route in Laravel 5.3:
Route::resource('bands', 'BandController');
The default route example coming when you start a new Laravel project has the following:
Route::get('/', function () {
return view('welcome');
});
How do I make bands route to be the default one when no controller is called instead of welcome? Meaning /?
I did read docs here but didn't found anything. Any?
Place that block inside laravel/app/routes.php instead of a Controller (4.x)
Place that block inside laravel/app/Http/routes.php instead of a Controller (5.1)
Place that block inside laravel/app/routes/web.php instead of a Controller (5.3)
Route::get('/', function()
{
return view('welcome');
});
You can redirect default to anywhere you want, i.e.:
Route::get('/', function()
{
return Redirect::to( '/bands');
// OR: return Redirect::intended('/bands'); // if using authentication
});
As #Patrick mentioned, you can simply redirect to the /bands route. However, I have to warn you that the redirect will actually change the URL in the navigation pane of the web browser. I would have suggested that you just ask the home route to use the index method of your BandController as follows:
Route::get('/', ['uses'=>'BandController#index']);

Can't route properly in Laravel

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.

Laravel Homestead Routing : InvalidArgumentException in compiled.php : View [****] not found

After getting my Laravel Homestead up and running, I'm facing a new problem.
Even after some googling, I can't find a solution for setting up routes in Laravel Homestead.
Here is my routes.php (I created files like in the comments) :
<?php
// ===============================================
// STATIC PAGES ==================================
// ===============================================
// show a static view for the home page (app/views/home.blade.php)
Route::get('/', function()
{
return View::make('home');
});
// about page (app/views/about.blade.php)
Route::get('about', function()
{
return View::make('about');
});
// work page (app/views/work.blade.php)
Route::get('work', array('as' => 'work', function()
{
return View::make('work');
}));
Route::get('users', function()
{
return View::make('users');
});
Thank you in advance for any piece of advice.
In Laravel5 the views are located in
resources/views
and not in app/views
Place all your views to resources/views and it should work.
You get the welcome page because it is shipped by default in Laravel.

Missing some more adjustments to make routing work in Laravel

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.

Categories