Cannot access files uploaded by Dropzone.js in Laravel Controller - laravel

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.

Related

I make Comment by Ajax but its not working

I make Comment by Ajax but its not working. It can insert and I already recived the data form controller. I check alert is display but html not display.
Here is my Route: Route::post('/addComment', 'LessonController#addComment');
Here is my controller
public function addComment(Request $request)
{
$lesson_id = $request->lesson_id;
$name = $request->name;
$body= $request->body;
$comment = new Comment();
$comment->name = $name ;
$comment->body = $body;
$comment->lesson_id = $lesson_id;
$comment->save();
return response()->json($comment);
}
Here is view comment create
<div class="leave_review">
<h3 class="blog_heading_border"> Leave a Comment </h3>
{!! Form::open(['action' => 'LessonController#addComment', 'method' => 'POST', 'id' => 'comment' ]) !!}
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<input type="hidden" id="lesson_id" name="lesson_id" value="{{$lesson->id}}" />
</div>
<div class="row">
<div class="col-sm-6">
{{Form::label('name','Name')}}
{{Form::text('name', '', ['class' => 'form-group', 'id'=>'name']) }}
</div>
<div class="col-sm-12">
{{Form::label('body','Message')}}
{{Form::textarea('body', '', ['class' => 'form-group', 'id'=>'body']) }}
</div>
</div>
<div class="row">
<div class="col-md-12">
</div>
</div>
{{Form::submit('Submit', ['name'=>'submit', 'class' => 'mt_btn_yellow pull-right'])}}
{!! Form::close() !!}
<br>
Here is comment display view blade
<div id="commen_show">
#foreach ($comment as $item)
<ol class="review-lists">
<li class="comment">
<div class="activity_rounded">
<img src="/storage/Iconimage/about.png" alt="image"> </div>
<div class="comment-body">
<h4 class="text-left">{{$item->name}}
<small class="date-posted pull-right">{{$item->created_at}}</small>
</h4>
<p>{{$item->body}}</p>
Reply
<div class="clearfix"></div>
</div>
</li>
</ol>
#endforeach
</div>
</div>
Here is my javascript, I think something wrong with append
<script>
$(document).ready(function($){
$('#comment').on('submit', function(){
var lesson_id = $('#lesson_id').val();
var name = $('#name').val();
var body = $('#body').val();
var _token = $('input[name="_token"]').val();
$.ajax({
type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
url : "{{url('/addComment')}}", // the url where we want to POST
data: {_token:_token, lesson_id:lesson_id, body:body, name:name},
success: function(response) {
if(response){
$('#commnet_show').prepend(
` <ol class="review-lists">
<li class="comment">
<div class="activity_rounded">
<img src="/storage/Iconimage/about.png" alt="image"> </div>
<div class="comment-body">
<h4 class="text-left">${response.name}
<small class="date-posted pull-right">${response.created_at}</small>
</h4>
<p>${response.body}</p>
Reply
<div class="clearfix"></div>
</div>
</li>
</ol> `
;);
}
}
});
});
});
</script>

Laravel - How to Pass a variable to controller and to url name of route

I need to pass variable to controller of details of Boat and show it in the url.
This is the blade view where I download a list of boats available:
#foreach($Boats as $boat)
<article class="box">
<figure class="col-sm-4">
<a title="" href="{{asset('frontend')}}/ajax/cruise-slideshow-popup.html" class="hover-effect popup-gallery"><img width="270" height="160" alt="" src="{{ json_decode($boat->images, true)['url']}}"></a>
</figure>
<div class="details col-sm-8">
<div class="clearfix">
<h4 class="box-title pull-left">{{$boat->name}}<small>{{$boat->id}}</small></h4>
<span class="price pull-right"><small>from</small>$239</span>
</div>
<div class="character clearfix">
<div class="col-xs-3 cruise-logo">
<img src="http://placehold.it/110x25" alt="" />
</div>
<div class="col-xs-4 date">
<i class="soap-icon-clock yellow-color"></i>
<div>
<span class="skin-color">Date</span><br>{{$boat->year}}
</div>
</div>
<div class="col-xs-5 departure">
<i class="soap-icon-departure yellow-color"></i>
<div>
<span class="skin-color">Departure</span><br>{{$boat->homeBase}}
</div>
</div>
</div>
<div class="clearfix">
<div class="review pull-left">
<div class="five-stars-container">
<span class="five-stars" style="width: 60%;"></span>
</div>
<span>270 reviews</span>
</div>
select cruise
</div>
</div>
</article>
#endforeach
This is route route.php file to translate url:
return [
"login" => "login",
"register" => "register",
"listBoats" => "boats",
"contact" => "contact",
"detailedBoat" => "DetailBoat/{id}",
];
web.php :
Route::get(LaravelLocalization::transRoute('routes.detailedBoat'),('DetailedBoat'), function (\App\Boat $id) {
return $id;
});
DetailsBoat Controller:
public function __invoke($id)
{
echo $id;
return view('frontendViews.detailedBoat');
}
Result should be
http://localhost:8000/en/boats/{id}
The strange thing is that routes work perfectly based on app.php 'locale' setting, if i have 'en' i get http://localhost:8000/en/DetailBoat/1` and http://booking:8888/it/DettaglioBarca/%7Bid%7D switching language;
viceversa if have ['it'] on app.php i'm getting http://booking:8888/it/DettaglioBarca/1 and http://booking:8888/en/DetailBoat/%7Bid%7D in english.
Thank you

My view displays raw blade code

I'm new to Laravel and using ver 5.5. I have a simple view and when I run the code, instead of showing the rendered version, I see the Blade commands.
This is the view code:
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>{{ $title }}</h2>
</div>
<div class="pull-left">
{!! \App\Combine\BaseCombine::tableHeader($collection) !!}
{!! \App\Combine\BaseCombine::tableData($collection) !!}
{!! \App\Combine\BaseCombine::tableFooter($collection) !!}
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('transaction.index') }}"> Back</a>
</div>
</div>
</div>
#endsection
Here is the code in the controller that executes the view:
return view('general.genericTable',
[
'title' => __FUNCTION__,
'transactionID' => $transactionsID,
'type' => $type,
'collection' => TransactionCombine::agents($transactionsID, $type),
]
);
This is what I see when I execute the code:
#section('content')
{{ $title }}
{!! \App\Combine\BaseCombine::tableHeader($collection) !!} {!! \App\Combine\BaseCombine::tableData($collection) !!} {!! \App\Combine\BaseCombine::tableFooter($collection) !!}
Back
#endsection
What have I done wrong?

Laravel 5 Missing route doesn't throw Exception

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', '(.*)');

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