remove photo from validation and try it
Mar 12, 2020
15
Level 27
Call to a member function store() on null
Any clue why I get this error:
Call to a member function store() on null
ProfileController.php
public function store(Request $request)
{
$this->validate($request,[
'photo' => 'required',
'nim' => 'required',
'nama' => 'required',
'alamat' => 'required'
]);
$profile = new Profile;
// $profile->photo = $request->photo;
// storage/app/photo/random.jpg
$path = $request->file('photo')->store('public/photo');
$profile->photo = $path;
$profile->nim = $request->nim;
$profile->nama = $request->nama;
$profile->alamat = $request->alamat;
$profile->save();
Session::flash('flash', 'Data sudah tersimpan');
return view('admin.add_profile');
}
add_profile.blade.php
<form method="post" action="{{ url('profile') }}" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label>Photo</label>
<input class="form-control" name="photo" type="file" placeholder="Enter email">
</div>
<div class="form-group">
<label>NIM</label>
<input class="form-control" name="nim" type="text" placeholder="Enter NIM">
</div>
<div class="form-group">
<label>Nama</label>
<input class="form-control" name="nama" type="text" placeholder="Enter Name">
</div>
<div class="form-group">
<label>Alamat</label>
<input class="form-control" name="alamat" type="text" placeholder="Enter Address">
</div>
<br>
<button class="btn btn-primary">Submit</button>
ref: https://laracasts.com/discuss/channels/laravel/call-to-a-member-function-store-on-null-3
Please or to participate in this conversation.