Check your fillable array.
Nov 28, 2015
11
Level 34
Image upload file does not working
My from is like below:
<form method="post" enctype="multipart/form-data" action="/admin/projects" class="col-lg-8">
{{csrf_field()}}
<div class="form-group">
<label for="title">Proejct Name:</label>
<input type="text" name="title" id="title" class="form-control" value="{{old('title')}}">
</div>
<div class="form-group">
<label for="sub_title">Project Sub_title:</label>
<input type="text" name="sub_title" id="sub_title" class="form-control" value="{{old('sub_tile')}}">
</div>
<div class="form-group">
<label for="photo">Photo:</label>
<input type="file" name="file" id="file" class="form-control" value="{{old('file')}}">
</div>
<button type="submit">Submit</button>
@if(count($errors)>0)
<div class="alert alert-danger">
<ul>
@foreach($errors->all()as $error)
<li>{{$error}}</li>
@endforeach
</ul>
</div>
@endif
</form>
and my controller:
public function store(ProjectRequest $request)
{
$file=$request->file('file');
$name=time().$file->getClientOriginalName();
$file->move('images/client',$name);
Project::create(['photo'=>"images/client/{$name}"]);
$request->all();
Project::create($request->all());
return 'Done';
}
image path does not create on database.Please help me
Level 41
This should work:
public function store(ProjectRequest $request)
{
$file = $request->file('file');
$name = time().$file->getClientOriginalName();
$file->move('images/client', $name);
$data = array_merge(['photo' => "images/client/{$name}"], $request->all());
Project::create($data);
return 'Done';
}
2 likes
Please or to participate in this conversation.