Are you sending the admin_id through a form? What does your view look like?
Jul 7, 2016
22
Level 2
Undefined index: admin_id
I have a table for admin and another table for admin picture, i set a relation between them like this
in Admin Model public function adminpicture() { return $this->hasOne('App\Adminpicture'); }
and in Adminpicture Model
public function admin()
{
return $this->BelongsTo('App\Admin');
}
here is migrations for both table
Schema::create('admins', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('adminpictures', function (Blueprint $table) {
$table->increments('id');
$table->string('file_name');
$table->integer('admin_id')->unsigned();
$table->timestamps();
$table->foreign('admin_id')->references('id')->on('admins')->onDelete('cascade');
});
My controller method for upload picture is here
public function addPicture()
{
if(Input::hasFile('file'))
{
$file = array('file' => Input::file('file'));
$rules = array('file' => 'required|mimes:jpg,png,jpeg');
$validator = Validator::make($file, $rules);
if ($validator->fails()) {
echo 'Not allowed!!';
}
else
{
if (Input::file('file')->isValid()) {
$destinationPath = 'AdminPicture';
$extension = Input::file('file')->getClientOriginalExtension();
$fileName = Auth::guard('admin')->user()->id.'.'.$extension;
if (File::exists($fileName))
{
File::delete($fileName);
}
else {
$displayImage = Input::file('file')->move($destinationPath, $fileName);
$request['file_name'] = $fileName;
$request['admin_id'] = $_GET['admin_id'];
Adminpicture::create($request);
echo 'Upload Succesfully <br>';
}
}
else {
Session::flash('error', 'uploaded file is not valid');
return Redirect::to('admin');
}
}
}
else
{
echo 'Nothing to upload';
}
}
but i get this error, please help me to solve out this problem and after that i want to display this picture also i view
Level 47
Your database name is illegal. Expect many problems. Fix the name first. http://stackoverflow.com/questions/9537771/mysql-database-name-restrictions
Please or to participate in this conversation.