Laravel: Pages not loading properly - laravel

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:
And then, after uploading the file:
this page loads:
2. yield('content') is not working. Although #include is working fine.
3. 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?

Related

Laravel pagination on each side not working properly

In my Laravel (5.7) controller, I have set pagination + 'on each side navigation' to 2 items. However, this is not working on my view. I'm getting much more items than 2, which causes my window to break out on small mobile devices.
What can be the cause of this and how can I fix it? I mean, I can get it fixed with CSS, but I would like to get it fixed the proper way.
My code in the controller:
public function index(Request $request)
{
$type = 'all';
if ($request->has('type')) {
if ($request->type == 'all') {
$materials = Material::paginate(10)->onEachSide(2);
} else {
$type = $request->type;
$materials = Material::where('type', $type)->paginate(10)->onEachSide(2);
}
} else {
$materials = Material::paginate(10)->onEachSide(2);
}
$stock = array(
'enkelzitKajaks' => Material::where('type', 'Enkelzitkajak')->count(),
'dubbelzitKajaks' => Material::where('type', 'Dubbelzitkajak')->count(),
'canadeseKanos' => Material::where('type', 'Canadese kano')->count(),
'langePeddels' => Material::where('type', 'Lange peddel')->count(),
'kortePeddels' => Material::where('type', 'Korte peddel')->count(),
'tonnetjes' => Material::where('type', 'Tonnetje')->count(),
'zwemvesten' => Material::where('type', 'Zwemvest')->count()
);
return view('materials.index')->with('materials', $materials)->with('stock', $stock)->with('type', $type);
}
My code in the view:
<section class="pagination">
<div class="container">
<div class="row">
<div class="col-12">
{{ $materials->links() }}
</div>
</div>
<hr>
</div>
</section>
A screenshot of my view on small devices:
First of all The laravel pagination onEachSide(x) has leading and tailing parts besides the middle section. Leading two pages and tailing two pages.
You are trying with onEachSide(2) and on the 6th page. So now we try to look at the logic in pagination.
In laravel when using onEachSide(2) it will show pagination like this
leadingTwoPages
currentPage - 2
currentPage
currentPage +2
tailingTwoPages
1,2
4,5
6
7,8
22,23
Then think about the first part of pagination it needs to show the 1st page to the 8th page without the 3rd page.
Instead of page number three, it needs to be a show button with dots.
Then instead of showing a button with dots for page number three, it will show the original 3rd-page number.
After the 6th page the laravel pagination onEachSide(2) will work fine
You can try class="pagination pagination-sm" for mobile device
It's because of a bug in Laravel 5.* versions. If you don't want to upgrade your app, you should manually change some codes in:
vendor/laravel/framework/src/illuminate/Pagination/UrlWindow.php
as mentioned and discussed in below link with Taylor Otwell.
Disccus about on each side bug in Laravel 5.*
You should use onEachSide this in blade.
Remove the onEachSide from the controllers. Using onEachSide in controllers will be helpful when you are creating APIs. Instead use onEachSide in blade file.
<section class="pagination">
<div class="container">
<div class="row">
<div class="col-12">
{{ $materials->onEachSide(1)->links() }}
</div>
</div>
<hr>
</div>
</section>
Use can manage the link window by changing the parameter in onEachSide
https://laravel.com/docs/8.x/pagination#adjusting-the-pagination-link-window

laravel rendering section no passing parameters data

i have a problem passing variable during the rendering of only a section
All works good but array of data passed to the section('sidebar') view create an error ($data doesn't exist)
My blade files are
Default.blade.php
..other html code before..
<body>
#include('includes.header')
<div class="container-fluid">
<div class="row">
#yield('sidebar')
<!-- main content -->
#include('includes.main')
</div>
<footer class="row">
#include('includes.footer')
</footer>
</div>
</body>
..other code after..
home.blade.php
#extends('layouts.default')
#section('sidebar')
#include('includes.sidebar')
#stop
sidebar.blade.php
..other html code before..
<h2>The current UNIX timestamp is {{ time() }}.</h2>
<ul>
#isset($data)
#foreach ($data as $item)
<li class="nav-item"> {{$item->polizza}}</li>
#endforeach
#endisset
</ul>
..other html code after..
Controller Method search
public function search(Request $request){
if ($request->ajax()) {
$data = Customers::select('id','contr_nom','email','targa','cliente')
->where('polizza',request('polizza'))
->get();
return view('pages.home',$data)->renderSections()['sidebar'];
}
//return json_encode($data);
}
I know that array $data is good because i try return just JSON and i know that just sidebar refresh because timestamp change.
But $data is not passed to sidebar section refreshed!!
Why?
Thks a lot
You have the right idea, you just need to send the variable in a form that will be recognized. I'll break it out to an extreme, to help understand the parts, but you can easily recombine for shorter code.
$view = view('pages.home', compact('data')); // Compact with the text name ('data') sends the variable through
$sections = $view->renderSections(); // returns an associative array of 'content', 'pageHeading' etc
return $sections['sidebar']; // this will only return whats in the sidebar section of the view
Using compact() should get your where you need, and is the key.

CKEditor issue with Laravel 5

I have a problem with CKEditor, it return me this result : <p style="text-align:center"><span style="font-family:Lucida Sans Unicode,Lucida Grande,sans-serif"><span style="font-size:14px">News content blah blah blah</p> instead of the text itself. I did successfully loaded the editor to form. Here is the form code :
{!! Form::textarea('abstrak', null, ['class' => 'form-control ckeditor']) !!}
the view that supposed to show the result :
<h5>{{ $jurnal->abstrak }}</h5>
and I load the js file from master template :
<script src="{{ asset('ckeditor/ckeditor.js') }}"></script>
is there something I missed here ? thankyou
Instruct Laravel Blade to not escape HTML characters by replacing your code with
<h5>{!! $jurnal->abstrak !!}</h5>

Laravel white page loading route

I had a login.blade.php with some code, and I decided to replace with a new one.
I renamed it to old_login.blade.php and create a new file, in the same path, with the name login.blade.php.
After a while, I decided to rollback to my old login page.
I delete login.blade.php, and renamed the old_login.blad.php with the original name to return back.
No code was edited, only views.
The problem is that the page returned a blanck white page with many comments (the comment's tag is not closed).
I try to make a copy of the view, called test.blade.php, and change the route to that view. It diplay them correctly. But If I change another time route to myapp.login to display login.blade.php view, it won't work.
I try anything but nothing is changed. I'm using laravel 5.1.
The code insiede my routes.php is
Route::get('/', function () {
return view('myapp.login');
});
the code inside the login.blade.php (same ad test.blade.php) is:
#extends("app")
#section("content")
{!! Form::open(["url" => "home"]) !!}
<div class="form-group">
{!!Form::label("username", "Username:") !!}
{!!Form::text("usr_username", "Luca", ["class" => "form-control"]) !!}
</div>
<div class="form-group">
{!!Form::label("password", "Password:") !!}
{!!Form::input("password", "usr_password", "mypass", ["class" => "form-control"]) !!}
</div>
<div class="form-group">
{!!Form::submit("Login", ["class" => "btn-primary form-control"]) !!}
</div>
{!! Form::close() !!}
#include("errors.list")
#stop
So a nonsense answer to resolve my problem: I cutted the code inside login.blade.php, save file, pasted it, and saved another time. Now it display correctly.

ajaxLink and multiple instances of jQuery

I am working in Zend-Framework. I have a layout something like this:
<html>
<head>
<script>
function myBeforeSendCallbackJsFunc() {$('#content-loading').show();}
function myCompleteCallbackJsFunc() {$('#content-loading').hide();}
</script>
</head>
<body>
<div id="menu">
<?php
echo $this->ajaxLink("<li>MENU 1</li>", '/controllertest/actionindex', array('update' => '#content', 'beforeSend' => 'myBeforeSendCallbackJsFunc();', 'complete' => 'myCompleteCallbackJsFunc()'), array('format' => 'ajax'));
?>
</div>
<div id="content">
</div>
<?php echo $this->jQuery()->enable()->uiEnable(); ?>
</body>
</html>
In this case the ajaxLink function works perfectly.
I fire the MENU 1 and '#content' gets the '/controllertest/actionindex' content.
But if exists ajaxLink functions inside the'/controllertest/actionindex' it only works if I include again:
<?php echo $this->jQuery()->enable()->uiEnable(); ?>
Why?
When calling the AjaxLink helper repeatedly in some inclusions via ajax I was generating multiple instances of the ajax function created by this helper.
When called asynchronously, the AjaxLink creates confusion.
The solution: don't use AjaxLink, and create a global and unique ajax function.

Resources