3

So I've been trying to learn laravel, but I've run into trouble pretty quickly and can't seem to find an answer to my problem. My routes.php file looks like

<?php

Route::get('/', 'PagesController@welcome');
Route::get('about', 'PagesController@about');

and PagesController.php looks like

<?php namespace App\Http\Controllers;

    use App\Http\Requests;
    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PagesController extends Controller {

        public function welcome(){
            return view('welcome');
        }

        public function about() {
            $name = 'My name';

            return view('about')->with('name', $name);  
        }

    }

Finally, about.blade.php looks like this:

<html>
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>

        <h1>About Me: {{ $name }}</h1>

        <p>
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

        </p>
    </body>
</html>

When I try to load about about.blade.php nothing shows up in my web browser, and view page source reveals that there's no html there. But when I rename about.blade.php to about.php the file loads, except the {{ $name }} part doesn't get rendered by blade like it should. The reason I'm especially confused is because welcome.blade.php, which is just the default welcome view for a new laravel project, loads just fine, as does the blade formatting stuff in it.

xsami
  • 1,312
  • 16
  • 31
Pastramifest
  • 41
  • 1
  • 4
  • Is the view in the 'app/views' folder? – Kenmore Apr 07 '15 at 00:47
  • @Zuko It's in 'resources/views', which I think is correct for laravel 5. – Pastramifest Apr 07 '15 at 00:59
  • Is your storage directory writable? If you're getting blank screen, it is very likely that something is wrong with permissions and nothing can't be written to `storage/framework/views` directory as a result. – kajetons Apr 07 '15 at 07:04
  • turn on all [**error reporting**](http://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings) – itachi Apr 07 '15 at 12:18
  • Ah, so much has changed in 5. I'm not up to date. – Kenmore Apr 07 '15 at 20:35
  • Thanks for that. I turned it on, and now it says there's an uncaught 'UnexpectedValueException' in 'vendor/compiled.php', except I have no idea what could be causing it – Pastramifest Apr 07 '15 at 21:12

3 Answers3

0

Try this..

from

return view('welcome');

to
  return View::make('welcome');

AND 

From

 return view('about')->with('name', $name); 

to

 return View::make('about')->with('name', $name); 
Deenadhayalan Manoharan
  • 5,436
  • 14
  • 30
  • 50
  • tried it, but now neither about.blade.php or about.php will load, and welcome.blade.php won't load either – Pastramifest Apr 07 '15 at 06:51
  • 1
    This won't fix anything since both `view()` and `View::make()` resolve to `Illuminate\View\Factory::make()` behind the scenes. – kajetons Apr 07 '15 at 07:09
0

I had the same problem, also with about.blade.php file. When I renamed the file into abou.blade.php (without 't'), everything worked like expected. I tried several times more (with other words like ab.blade.php, abouts.blade.php,...) and i could not believe that the problem was the file naming (but it was). After couple of tests more, i found that the problem really was file permissions.

I work on Ubuntu and I saw that my permissions for /var/www/html folder were reset, so i needed to do 'chmod -R 777 /var/www/html/' once again.

anchor
  • 755
  • 2
  • 8
  • 17
  • What you did was give everyone full permissions. This is definitely not the solution.. – ImAtWar Mar 22 '16 at 13:35
  • You are right, it is not the way to go, but this was done on local machine (not on live server). I just wanted to point out that this is a permission problem... – anchor Mar 24 '16 at 09:27
0

Try return redirect('about')->with('name', $name);

Sled
  • 18,541
  • 27
  • 119
  • 168