User's avatar
Level 1

Laravel: Pages not loading properly

This might look useless question, but I'm unable to understand the problem here. The problems are:

  1. When I load the page, first this loads: a page containing "Upload files here" form

And then, after uploading the file: this page loads: another "Upload files here" form

  1. yield('content') is not working. Although @include is working fine.

  2. I made master.blade.php, to load the first page of the website. Before it, I was working on the welcome page.But, then changed the work of welcome with the master blade, but when the page gets loaded, it doesn't show anything.

Routes:

Route::get('/',function() {
return view('welcome');
});

Route::group(['middleware' => ['web']], function(){
Route::get('upload',function(){
    return view('pages.upload');
});

Route::post('/upload','UploadController@upload');
});

views/pages/upload:

@extends('welcome')
@section('content')
<h2>Upload Files Here</h2>

{!! Form::open(array('url' => '/upload','files'=>true))!!}
 {!! Form::file('file') !!}
 {!! Form::token() !!}
 {!! Form::submit('Upload') !!}
{!! Form::close() !!}
@endsection

views/welcome:

<!DOCTYPE html>
<html lang="en">
<head>
@include('partials._head')
 </head>
 <body>
         @include('partials._nav')
         <div class="container">
         @include('partials._messages')
         @yield('content')
         @include('partials._footer')
         </div>
 @include('partials._javascript')

UploadController/Controllers:

if($request->hasFile('file')){
        $file = $request ->file('file');

        $fileName = $file->getClientOriginalName();

        $destinationPath = config('app.fileDesinationPath').'/'.$fileName;

        $uploads = Storage::put($destinationPath,file_get_contents($file- >getRealPath()));
}
    return redirect()->to('/upload');

When it's working fine when I used include, to include the upload page in welcome, but the result is like shown in the pictures.Also, When I tried to use the master blade, and exclude the use of the welcome page, by erasing the content of the welcome page, the blank page gets loaded. What changes do I have to make to make use of master instead of the welcome page? Why are two pages getting loaded? also, why isn't yield('content') not working?

Also, the file which I'm uploading is not getting saved in the public/uploads folder.

Please, can anyone help?

0 likes
4 replies
Snapey's avatar

can you go back and put three backticks ` before and after each code block

1 like
User's avatar
Level 1

@Snapey Did it. Thank you. Actually, this is my first time here. Now, can you give any hint about my question?

mdecooman's avatar

Hi @User

What version of Laravel are you using?

Your yield statement seems correct but you are talking about a master page but your code above does not extend it. It still extends the welcome page.

You seem to have a typo in your controller:

$file- >getRealPath()  //a space between - and >

I would suggest to install debugbar to help you debug your issue (or use chrome dev tool extension):

https://github.com/barryvdh/laravel-debugbar (see instructions):

composer require barryvdh/laravel-debugbar --dev

...

Try to tackle one problem at a time. Seems to me that you want to run before walking.

Hope this help.

1 like
User's avatar
Level 1

No, No. I was dealing with one problem at a time. Actually, the problem with yield didn't solve from a ver long time, but the files were being uploaded and the screen was one. Then I was trying to connect the files being uploaded by the user with the database and changed the code a little bit, and then the other two errors occurred @mdecooman

Please or to participate in this conversation.