Laravel 5 Missing route doesn't throw Exception - laravel

I'm having an issue my missing routes behaviour. If I try a random URL no exception is thrown I get an
Undefined variable: errors
instead of the 404 page that I have created. The thing is that if I try to access an object that doesn't exist in database from a valid existing route, the 404 error is thrown and the page is rendered like it should.
I have a layout for my error pages that includes a topbar and within that bar there is a modal form that I include in the master layout(the undefined error comes from that modal apparently):
mastererror.blade.php:
<!DOCTYPE html>
<html>
<head>
<title>#yield('title')</title>
<!-- Load CSS -->
#include('assets.css')
<!-------------->
<!-- Load jQuery -->
<script src="{{ URL::asset('js/jquery-2.1.4.min.js')}}"></script>
<!----------------->
</head>
<body>
<!-- Load Navbar -->
#include('elements.html.navbartop')
<!----------------->
<div class="pusher">
<div id="content" class="ui main container" style="margin: 70px 0px 50px 0px">
<!-- Load Content -->
#yield('content')
<!------------------>
</div>
</div>
<!-- Load Footer -->
#include('elements.html.footer')
<!----------------->
<!-- Load JavaScript -->
#include('assets.js')
<!--------------------->
<!-- Load login Modal -->
#include('elements.html.partials.login-modal')
<!---------------------->
</body>
</html>
404.blade.php:
#extends('layout.mastererror')
#section('title', 'Not Found.')
#section('content')
<div style="margin-top: 30px">
<img class="ui medium image centered" src="{{asset('images/notfound.png')}}">
<h1 class="ui header centered">404 Not Found.</h1>
#if($exception->getMessage() !== '')
<h2 class="ui header centered">{{ $exception->getMessage() }}.</h2>
#else
<h2 class="ui header centered">The resource is missing.</h2>
#endif
<h3 class="ui header centered">Home </h3>
</div>
#endsection
login-modal.blade.php:
<div class="ui small modal" id="loginModal">
<i class="circular close icon inverted"></i>
<div class="header">
Login
</div>
<div class="ui active dimmer" id="loader" style="display: none">
<div class="ui text loader">Loading</div>
</div>
<div class="content">
<div class="ui grid">
<div class="eight wide column centered">
{!! Form::open(array('route' => 'auth.login', 'method' => 'post','id'=>'formLogin','class' => 'ui large form')) !!}
<div class="field {!! $errors->has('username') ? 'error' : '' !!}">
<div class="ui left icon input">
<i class="user icon"></i>
{!! Form::text('username','',['name'=>'username','id'=>'username','class' => 'pd','placeholder'=>'Pseudo']) !!}
</div>
{!! $errors->first('username', '<span class="ui text" id="" style="color: #bf4d4b">:message</span>') !!}
</div>
<div class="field {!! $errors->has('password') ? 'error' : '' !!}">
<div class="ui left icon input">
<i class="lock icon"></i>
{!! Form::password('password',['name'=>'password','id'=>'password','class' => '','placeholder'=>'Mot de passe']) !!}
</div>
{!! $errors->first('password', '<span class="ui text" id="" style="color: #bf4d4b">:message</span>') !!}
</div>
{!! Form::submit('Login',['id'=>'loginButton','class'=>'ui fluid large teal submit button']) !!}
{!! Form::close() !!}
<div class="ui message">
<p>Mot de passe oublié? {{ link_to_route('password.forgot','Réinitialiser',null,null) }}</p>
<p>Pas encore membre? {{ link_to_route('auth.register','s\'Enregistrer',null,null) }}</p>
</div>
</div>
</div>
</div>
</div>

The magic $errors variable is not generated when an error is thrown (discussed in more detail here: https://github.com/laravel/framework/issues/11457).
You'll need to do an isset($errors) on any templates you include that reference $errors
<div class="field {!! isset($errors) ? ( $errors->has('username') ? 'error' : '' ) : '' !!}">

for now I added this route to catch any invalid routes:
Route::any('{catchall}', function($page){
abort(404,"the page '$page' doesnt exist");
})->where('catchall', '(.*)');

Related

issue when redirect to livewire component

i installed livewire successfully but when i return the page and the page has
this
#livewire('counter')
it returns error
Livewire\Redirector::component(): Argument #1 ($component) must be of type Livewire\Component, App\Http\Livewire\Counter given
here is my test page
#extends('layouts.master')
#section('css')
#section('title')
empty
#stop
#endsection
#section('page-header')
<!-- breadcrumb -->
<div class="page-title">
<div class="row">
<div class="col-sm-6">
<h4 class="mb-0"> </h4>
</div>
<div class="col-sm-6">
<ol class="breadcrumb pt-0 pr-0 float-left float-sm-right ">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active">Page Title</li>
</ol>
</div>
</div>
</div>
<!-- breadcrumb -->
#endsection
#section('content')
<!-- row -->
<div class="row">
<div class="col-md-12 mb-30">
<div class="card card-statistics h-100">
<div class="card-body">
#livewire('counter')
</div>
</div>
</div>
</div>
<!-- row closed -->
#endsection
#section('js')
#endsection
and my livewire/counter.blade.php page
<div>
hello world
</div>
and route
Route::get('test', function () {
return view('test');
});

i recently used JCrop in my laravel project , but although i choose a photo and its loaded , i get validation error image is requred

I followed this https://www.youtube.com/watch?v=aflTCbGdzDc tutorial, and I managed to include Jcrop in my laravel project, everything is working fine. I click on choose image, I crop the image, and the image is shown in the jcrop image box. but when I submit the form. I get the error in my validation that says, image is required ( i wrote a validation for my image file). why am I getting this error ??? the image is showing in that box. what am I doing wrong ? or is there a problem with JCrop ?!! please help me.
This is the image when I upload :
https://drive.google.com/open?id=1qgEmA9RlKy_eilZohCLajGmnVfqWSB9E
This is the image when I submit and I get the error : https://drive.google.com/open?id=1gSCurwZ50TF_nMZZcWnJ4keBsJmcQKEh
Template Code:
<form method="post" action="{{route('userRegister')}}" enctype="multipart/form-data">
#csrf
<div class="col-md-6 alert alert-danger {{!empty($errors->all()) ? 'show' : 'hide'}}">
<ul style="text-align: right;" dir="rtl">
#foreach($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
<div class="row col-md-12" dir="rtl">
<div class="input-group col-md-4">
<div class="container" dir="ltr">
<div id="userpic" class="userpic">
<div class="js-preview userpic__preview"></div>
<div class="btn btn-success js-fileapi-wrapper">
<div class="js-browse">
<span class="btn-txt">انتخاب عکس</span>
<input type="file" name="filedata" id="filedata" >
</div>
<div class="js-upload" style="display: none;">
<div class="progress progress-success"><div class="js-progress bar"></div></div>
<span class="btn-txt">در حال بارگذاری</span>
</div>
</div>
</div>
</div>
<div id="popup" class="popup" style="display: none">
<div class="popup__body"><div class="js-img"></div></div>
<div style="margin: 0 0 5px;text-align: center">
<div class="js-upload btn btn_browse btn_browse_small">بارگذاری</div>
</div>
</div>
</div>
</div>
Validation Code:
public function rules()
{
return [
'filedata' => 'required|max:1024',
];
}
public function messages()
{
return [
'filedata.max' => 'سایز تصویر نمیتواند بیش از 2 مگابایت باشد',
'filedata.required' => 'وارد کردن تصویر الزامی است',
];
}
I get this error in my console :
POST http://localhost:8000/server/ctrl.php?fileapi155834626282411 404 (Not Found) FileAPI.min.js:2
After talking to you in the comments, it would appear your getting 404 errors on the FileAPI javascript files.
You were using the following configuration for your FileAPI:
var FileAPI = { debug:true, media:true, staticPath:'{{asset('crop-userpic\FileAPI')}}' };
This was setting your staticPath to the /resources/assets/crop-userpic/FileAPI directory, which placed them outside of the webroot of your website.
You need to set the staticPath to the location of the FileAPI javascript files within your public directory so they can be accessed by jcrop.
Example Usage
<!-- include jquery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<!-- Set FileAPI settings -->
<script>
window.FileAPI = {
debug: false,
media: true,
staticPath: '/js/jquery.fileapi/FileAPI/'
};
</script>
<script src="/js/jquery.fileapi/FileAPI/FileAPI.min.js"></script>
<script src="/js/jquery.fileapi/FileAPI/FileAPI.exif.js"></script>
<script src="/js/jquery.fileapi/jquery.fileapi.min.js"></script>
<script src="/js/jcrop/jquery.Jcrop.min.js"></script>
In the above example staticPath is the path to the files FileAPI.min.js and FileAPI.exif.js.
You should make sure you have those files accessible from within the /public/js/jquery.fileapi/FileAPI/.

Cannot access files uploaded by Dropzone.js in Laravel Controller

There is a model called Image and it has a file, title, photographer and etc. I need to let the users to upload multiple images, then display the form of other fields for each image. So I chose Dropzone and I need to do it without Ajax upload. This is the form
#extends('layouts.layout')
<link rel="stylesheet" href="{{asset('css/dropzone.css')}}" />
#section('content')
<div class="container">
<div class="row">
<div class="col-md-12 text-right">
<div class="widget">
<div class="widget-header">
<span> Multi Image Upload </span>
<i class="icon-picture mr-2"></i>
</div>
<div class="widget-content">
#include('layouts.message')
<SECTION>
<DIV id="dropzone">
{!! Form::open([ 'route' => [ 'images.multiUploadStore' ], 'files' => true, 'enctype' => 'multipart/form-data', 'class' => 'dropzone py-5 px-1 text-center w-100', 'id' => 'image-upload' ]) !!}
<DIV class="dz-message needsclick" id="demo-upload">
Drag and Drop Your Files Here
</DIV>
<div class="mx-auto text-center clearfix col-sm-12">
{{Form::submit('Submit',['class'=>'btn btn-primary','name'=>'submit', 'id'=>'submit'])}}
</div>
{!! Form::close() !!}
</DIV>
</SECTION>
</div>
</div>
</div>
</div>
</div>
#endsection
#section('scripts')
<script src="{{asset('js/dropzone.js')}}"></script>
<script>
Dropzone.options.imageUpload = {
maxFilesize : 1,
acceptedFiles: ".jpeg,.jpg,.png,.gif"
};
</script>
#endsection
and this is the controller
public function multiuploadstore(Request $request)
{
$images = $request->file('file');
dd($images);
}
and it returns null. How can I access files inside the controller?
Thanks in advance.

Merging dropzone.js with my form

I'm creating a form that uses dropzone.js, I've managed to do it by having the drag and drop image by itself. The problem I'm having is that I'm struggling to merge dropzone with the form I'm having. If I add the dropzone class to my form then my whole form is the dropzone but I just want a section to be the dropzone.
Hope I explained it properly.
Here is my create.blade.php
{{ Form::open(array('route' => 'menus.store', 'class' => 'add-form')) }}
<div class="form">
<div class="parents_input">
<div>
{{ Form::label('menu_id', 'Parent Menu')}}
</div>
<div>
{!! Form::select('menu_id', $menu_id->prepend('Please Select', '0'), null, array("class" => "form-control")) !!}
</div>
</div>
<div class="title_input">
<div>
{{ Form::label('title', 'Title') }}
</div>
<div>
{{ Form::text('title','', array('id' => 'title', "class" => "form-control")) }}
</div>
</div>
<input type="file" name="file" class="dropzone" id="my-awesome-dropzone" />
<div class="layout_type">
<input id="home" type="radio" value="home" name="type">
<label for="home">Home</label>
<input id="stories" type="radio" value="stories" name="type">
<label for="stories">Stories</label>
</div>
<div class="submit_button">
<div>
{{ Form::submit('Submit', array("class" => "btn btn-info submit", "role" => "button")) }}
</div>
</div>
</div>
{{ Form::close() }}
you have to add dropzone in one separate div.
<script src="../../assets/dropzone/js/dropzone.js"></script>
<link type="text/css" rel="stylesheet"
href="../../assets/dropzone/css/dropzone.css">
<div class="">
<div action="" id="dZUpload" class="dropzone" method="post"
enctype="multipart/form-data">
</div>
</div>
after that initialise dropzone.

how to clear cache search results from server in laravel 5?

i'm new to laravel and i've created a simple search to query my database.
the problem is that everytime i refresh the page all the results from my last search are still showing. also when i load the page after couple of days,results are the. it seems like there is a cache working which i dont know about.
i want to clear these results/cache without clearing the cache for all my app.
Here is the code.
in my routs file:
Route::get('men',function()
{
$query=Request::get('q');
if ($query)
{
$users= \App\User::where('first_name','LIKE',"%$query%")
->orwhere('last_name','LIKE',"%$query%")
->get();
}
else
{
}
return view('page')->withUsers($users);
});
My View:(page.blade.php)
{!! Form::open(['method' => 'GET']) !!}
<div class="container col-lg-6 form-group" style="float:none;margin:auto">
<div class="input-group">
{!! Form::input('search','q', null, ['placeholder' => 'search' ,
'class' => 'form-control', 'autocomplete' => 'off']) !!}
<div class="input-group-btn">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Search</button>
</div><!-- /btn-group -->
</div><!-- /input-group -->
</div>
{!! Form::close() !!}
<div class="container col-lg-6" style="float:none;margin:auto">
#if ($users->count())
<ul class="list-group" style="list-style-type: none;">
#foreach($users as $user)
<li class="list-group-item" style="cursor:pointer">
{{$user->first_name}} {{$user->last_name}}
</li>
#endforeach
</ul>
#else
<h3>Sorry,no users found...</h3>
#endif
</div>
</div> <!--container-->
any Ideas ??..
i've managed to clear last query string in the browser addess bar with:
within my view:
<head>
<script type="text/javascript">
var uri = window.location.toString();
if (uri.indexOf("?") > 0) {
var clean_uri = uri.substring(0, uri.indexOf("?"));
window.history.replaceState({}, document.title, clean_uri);
}
</script>
</head>
whenever i refresh the page it clears up the results since nothing is coming from the server.

Resources