I'm working with related tables and this time I can insert the image name in the database, but I am not able to save the image in the folder giving this error Image source not readable
Some help?
Controller
public function InserirPortfolio(Request $request) {
$portfolio = Input::except('_token');
$portfolio['id'] = Input::get('id');
$validation = Validator::make($portfolio, Portfolio::$portfolio);
if ($validation->passes()) {
if($user = Portfolio::find($portfolio['id'])) {
$user -> update($portfolio);
Session::flash('editarportfolio', 'Portfolio editado com sucesso');
return Redirect::to('backend/portfolio');
}else{
$portfolio = new Portfolio();
$portfolio->title= Input::get('title');
$portfolio->year= Input::get('year');
$portfolio->save();
$image= new PortfolioImage();
if($request->hasFile('image')){
$file = array_get($portfolio,'image');
$destinationPath = 'image/portfolio/';
$extension = $request->file('image')->getClientOriginalExtension();
$fileName = rand(1111,9999) . '.' . $extension;
$student->image = $fileName;
Image::make($file)->resize(1000, 750)->save($destinationPath.$fileName);
}
$image->Portfolio()->associate($portfolio);
$image->save();
}
Session::flash('portfolio', 'success');
return Redirect::to('backend/portfolio');
} else {
return Redirect::to('backend/portfolio/editar/'.$portfolio['id'])->withInput()->withErrors($validation);
}
} return Redirect::to('backend/portfolio');
} else {
return Redirect::to('backend/portfolio/editar/'.$portfolio['id'])->withInput()->withErrors($validation);
}
}
Relation
class Portfolio extends Model
{
protected $table = 'portfolio';
protected $fillable = ['id','title','year','description'];
public function imageportfolio(){
return $this->hasMany('App\ImagePortfolio','id_portfolio','id')->first();
}
public static $portfolio = array(
'title' => 'required',
'year' => 'required',
'description' => 'required',
);
}
class ImagePortfolio extends Model
{
protected $table = 'imageportfolio';
protected $fillable = ['id','id_portfolio','image'];
public function portfolio() {
return $this->belongsTo('App\Portfolio', 'id_portfolio');
}
public static $imageportfolio= array(
'image' => 'image|max:3000|mimes:jpeg,jpg,png'
);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire