I am working on uploading the videos for my website. But i unable to do it. I have search many documents but i am fail to solve it. Can any one help me out to solve this problem?
I am getting an error "Call to a member function getClientOriginalName() on null"
//Form code for video upload..
{!! Form::open(array('url' => 'video' , 'files' => true)) !!}
<div class="form-group">
{!! Form::label('video_name', 'Video Name : ') !!}
{!! Form::text('name',null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('video_path', 'Select Video : ') !!}
{!! Form::file('path', ['class' => 'form-control'])!!}
</div>
<div class="form-group">
{!! Form::submit('Upload Video') !!}
</div>
{!! Form::close() !!}
//Controller Code
public function store(Request $request){
$data = $request->all();
if ( $request->hasFile( 'path' ) ) {
$file = $request->file( 'path' );
$name = $file->getClientOriginalName();
$data[ 'path' ] = $name;
$destination = '/public/videos';
$request->file( 'path' )->move( base_path() . $destination, $name );
return $name;
}
else {
return '<script>alert("Fail")</script>';
}
}
//The above code is working for images, doucments and audio but not working for videos.
Thanks in advance
If your uploaded video is larger than the upload setting in your php.ini then you get this problem.
I suggest check your php.ini file and increase these directives as needed
php.ini
Example
post_max_size=200M
upload_max_filesize=200M
Related
I am using laravel chart(laraveldaily)
controller
$options = [
'chart_title' => 'Animals by type',
'chart_type' => 'pie',
'report_type' => 'group_by_relationship',
'model' => 'App\Animal',
'relationship_name' => 'type', // represents function type() on Transaction model
'group_by_field' => 'category', // types.category
'filter_months' => 12, // show only transactions for last 30 days
];
$chart2 = new LaravelChart($options);
return view('admin.index', compact('users', 'chart2'));
In my view I have
<div class="row pl-lg-5" style="width: 40%;">
<h1>{{ $chart2->options['chart_title'] }}</h1>
{!! $chart2->renderHtml() !!}
<hr>
</div>
#section('scripts')
{!! $chart2->renderJs() !!}
{!! $chart2->renderChartJsLibrary() !!}
#endsection
I am getting only the title and there is no chart
Include the ChartJS library from CloudFlare before you render the JS code that uses Chart
#section('scripts')
{!! $chart2->renderChartJsLibrary() !!}
{!! $chart2->renderJs() !!}
#endsection
Hope this helps
I have a problem when import data xlsx using package fast excel.
I wanna input excel files include the Id from different model like following below
app/http/clustercontroller :
public function Import($id)
{
$model = Cluster::findOrFail($id);
return view('components.Admin.import', compact('model'));
}
public function StoreImport($id, Request $request)
{
//VALIDASI
$this->validate($request, [
'file' => 'required|mimes:xls,xlsx',
]);
if ($request->hasFile('file')) {
$file = $request->file('file'); //Get File
$collection = (new FastExcel)->import($file, function ($line) use ($id) {
return Soal::create([
'soal' => $line['Soal'],
'image' => $line['Image'],
'A' => $line['A'],
'B' => $line['B'],
'C' => $line['C'],
'D' => $line['D'],
'E' => $line['E'],
'kunci' => $line['Kunci'],
'cluster_id' => $id
]); //Import File
});
}
}
resource/admin/import.blade.php :
{!! Form::model($model, [
'route' => $model->exists ? ['cluster.soal.store', $model->id] : 'cluster.soal.create',
'method' => $model->exists ? 'POST' : 'POST',
'files' => true
]) !!}
<div class="form-group">
<label for="" class="control-label">Cluster</label>
{!! Form::text('cluster', null, ['class' => 'form-control', 'id' => 'cluster']) !!}
</div>
<div class="form-group">
<label for="" class="control-label">File .xlsx</label>
{!! Form::file('files') !!}
</div>
{!! Form::close() !!}
the code above displays the form, but when I click submit there is no response
You don't seem to return a response in your Controller method, so that's one reason I can think of. I assume your models are stored?
Things you could do to improve:
Return a view or, even better, redirection after finishing the import
Surround your code with try/catch blocks
I wish to make search query by datepicker and select field.
How could I get the requests values from below view file to controller?
Where could I modify in the code? thanks.
index.blade.php
<div class="form-group col-sm-6">
{!! Form::open(array('class' => 'form', 'method' => 'get', 'url' => url('/pdfs/job_finished_search'))) !!}
{!! Form::input('text', 'datepicker_from', null, ['placeholder' => 'Fra', 'id' => 'datepicker_from']) !!}
{!! Form::input('text', 'datepicker_to', null, ['placeholder' => 'Til', 'id' => 'datepicker_to']) !!}
{!! Form::select('customer_name', $jobs->pluck('customer_name', 'customer_name')->all(), null, ['class' => 'form-control']) !!}
{!! Form::submit('Søke', ['class' => 'btn btn-success btn-sm']) !!}
{!! Form::close() !!}
</div>
Controller.php
public function job_finished_search(Request $request, Job $jobs)
{
$jobs = Job::onlyTrashed()
->whereBetween('created_at', array(
(Carbon::parse($request->input('datepicker_from'))->startOfDay()),
(Carbon::parse($request->input('datepicker_to'))->endOfDay())))
->where('customer_name', 'like', '%'.$request->customer_name.'%')
->orderBy('deleted_at', 'desc')
->paginate(15);
if (empty($jobs)){
Flash::error('Search result not found');
}
return view('pdfs.index', ['jobs' => $jobs]);
}
There are multiple way to get the request data e.g to get datepicker_from value you can use any of the below
$request->datepicker_from
$request->input('datepicker_from')
$request->get('datepicker_from')
choose the one you like the most
refer to https://laravel.com/docs/5.5/requests
To get request values you can use the get method, try:
$customer = $request->get('customer_name','default_value');
To get request values, you can set an object like $input= $request->all(). Then you can make use of the object which is an array to get at specific fields, e.g to access your date picker, you can write $input['datepicker_from']. You need to place $input= $request->all() before you declare the $jobs object in your code.
I'm new with Laravel and I'm having problems while I try to detach some values from my pivot tables.
The pivot tables I'm woking with are:
excercise_workout (ejercicio_rutina) & excise_day (ejercicio_dia) (those tables have just two id's each one). The relations are ManyToMany. A workout have a lot of days and a day have a lot of excercises.
I've created these routes:
Route::resource('rutinas','RutinasController');
Route::delete('rutinas.destroyEjercicio/{id}','RutinasController#destroyEjercicio');
I have this button that is a form and call the delete:
{!! Form::open([
'method' => 'DELETE',
'action' => [ 'RutinasController#destroyEjercicio', $ejercicio->id ]
]) !!}
{!! Form::submit('Borrar Ejercicio', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
The destroyEjercicio is the part I don't know how to hadle with:
public function destroyEjercicio($id)
{
$ejercicio = Ejercicio::findOrFail($id);
dias()->$ejercicio->detach($id);
//EXAMPLE DELETE WITH QUERY
// DB::delete('delete from toy_user where toy_id = ? AND user_id = ? AND status = 0', array($toy->id,Auth::id()));
return redirect('rutinas');
}
I recieve this error when I try to submit the delete form:
Call to undefined function App\Http\Controllers\dias()
I've tried a lot of other methods but I don't know how to do it.
I need to know the ID of the day and the ID of the excercise I want to delete. And I don't know how the past it by the post request.
UPDATE -> THIS IS THE FORM I DO NOT HAVE INPUTS TO REQUEST...
#foreach ($rutina->dias as $dia)
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-body">
Ejercicios para el <strong>{{ $dia->nombre }}</strong>
<hr>
#foreach ($dia->ejercicios as $ejercicio)
<ul>
<li>{{ $ejercicio->nombre }}</li>
</ul>
{!! Form::open([
'method' => 'DELETE',
'action' => [ 'RutinasController#destroyEjercicio', $ejercicio->id ]
]) !!}
{!! Form::submit('Borrar Ejercicio', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
#endforeach
</div>
</div>
</div>
#endforeach
You need something like this:
public function destroyEjercicio($ejercicioId, $diasId)
{
$ejercicio = Ejercicio::findOrFail($ejercicioId);
$ejercicio->dias()->detach($diasId);
https://laravel.com/docs/5.1/eloquent-relationships#inserting-many-to-many-relationships
Update
How to use Request object. If you're using forms, Reuqest object will contain all form fields. Just do something like this:
public function destroyEjercicio(Request $request)
{
$ejercicioId = $request->get('ejercicioIdField');
$diasId = $request->get('diasIdField');
I solved this the following way. First I create this new route:
Route::post('rutinas.destroyEjercicio/{ejercicioId}/{diaId}', [
'as' => 'destroy',
'uses' => 'RutinasController#destroyEjercicio'
]);
You must add this array at the form:
{!! Form::open([
'method' => 'POST',
*******'route' => ['destroy', $ejercicio->id, $dia->id]******
]) !!}
{!! Form::submit('Borrar Ejercicio', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
Then in your controller you pass the two id's that you need:
public function destroyEjercicio($ejercicioId, $diaId)
{
$ejercicio = Ejercicio::findOrFail($ejercicioId);
$ejercicio->dias()->detach($diaId);
return redirect('rutinas');
}
I had created a form like the following in my view
{!! Form::open(array('url' => 'user/posts', 'files'=> true)) !!}
<div class="form-group">
{!! Form::text('title',Input::old('title'),['class'=>'form-control', 'placeholder' => 'What is your title?']) !!}
</div>
<div class="form-group">
{!! Form::label('image', 'Your Image') !!}
{!! Form::file('image') !!}
<p class="help-block">Hey! Please don't upload over 15MB images!</p>
</div>
<div class="form-group">
{!! Form::label('caption', 'Don\'t miss to caption!') !!}
{!! Form::text('caption',Input::old('caption'),['class'=>'form-control', 'placeholder' => 'Your caption']) !!}
</div>
{!! Form::submit('Post now!',['class'=>'btn btn-info']) !!}
{!!Form::close() !!}
And I try dd() for my image from my controller but it return nulll. The following one is my Controller
public function store(PostFormRequest $request)
{
dd($request->input('image'));
$post = new Post;
}
The following one is my PostFormRequest
<?php namespace App\Http\Requests;
use Response;
use Illuminate\Foundation\Http\FormRequest;
class PostFormRequest extends FormRequest {
public function rules()
{
return [
'title' => 'required',
'image' => 'mimes:jpeg,bmp,png'
];
}
public function authorize()
{
$image = $this->image;
if(empty($image))
return true;
else
return false;
}
public function forbiddenResponse()
{
return Response::make('Sorry!',403);
}
}
When I try dd($request->input('title')); it's return string(4) "test" what I was wrong?
For files you need to use:
dd($request->file('image'));
and not
dd($request->input('image'));
Reference
Faced with the same problem. One more little thing: if you use native HTML form submit you need also set 'enctype="multipart/form-data"'. Otherwise $request->file('INPUT_NAME') returns string instead the file.