简体   繁体   中英

Laravel .blade view won't load

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.

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); 

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM