Skip to content

Instantly share code, notes, and snippets.

@Moix1
Last active June 1, 2018 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Moix1/5dac37cdeb1e498d148aa12c33194da4 to your computer and use it in GitHub Desktop.
Save Moix1/5dac37cdeb1e498d148aa12c33194da4 to your computer and use it in GitHub Desktop.
I have problem in insertion of data with Laravel 5.6 ,I have controller In which I have written my code for storing form data after submission, In side this form I have three types of Image selection, mainPhoto as Single Image selection, otherPhotos multiple, fashionPhotos multiple and arabicPhotos also multiple, When i try to fill form and subm…
public function store(Request $request)
{
return $request;
$mainPhoto = $request->file('mainPhoto');
$otherPhotos = $request->file('otherPhotos');
$fashionPhotos = $request->file('fashionrPhotos');
$arabicPhotos = $request->file('arabicPhotos');
$slug = str_slug($request->name);
$model = new OurModels();
$model->name = $request->name;
$model->dateofBirth = $request->dateob;
$model->age = $request->age;
$model->height = $request->height;
$model->chest = $request->chest;
$model->waist = $request->waist;
$model->hips = $request->hips;
$model->eye = $request->eye;
$model->skin = $request->skin;
$model->shoes = $request->shoes;
$model->gender = $request->gender;
$model->haircolor = $request->haircolor;
$model->mobileNumber = $request->mobileNumber;
$model->email = $request->email;
$model->category = $request->category;
$model->mainPhoto = $request->mainPhoto;
$model->save();
$model->ethnicities()->attach($request->ethnicities);
// Main Photo Code Start
if(isset($mainPhoto))
{
$currentDate = Carbon::now()->toDateString();
$mainPhotoName = $slug .'-'. $currentDate .'-'. uniqid() .'-'. $mainPhoto->getClientOriginalExtension();
if(!file_exists('uploads/models/mainPhoto'))
{
mkdir('uploads/models/mainPhoto', 0777, true);
}
$mainPhoto->move('uploads/models/mainPhoto', $mainPhotoName);
}else{
$mainPhotoName = 'default.png';
}
// Main Photo Code End
// Other Photos Code Start
if(isset($otherPhotos)) {
if(!file_exists('uploads/models/otherPhotos')) {
mkdir('uploads/models/otherPhotos', 0777, true);
}
foreach($otherPhotos as $otherPhoto) {
$currentDate = Carbon::now()->toDateString();
$otherPhotoName = $slug.'-'.$currentDate.'-'.uniqid().'.'.$otherPhoto->getClientOriginalExtension();
$otherPhoto = new OtherPhoto();
$otherPhoto->our_models_id = $model->id;
$otherPhoto->image = $otherPhotoName;
Storage::disk('public')->put('uploads/models/otherPhotos', $otherPhotoName);
$otherPhoto->save();
}
}else{
$otherPhotoName = "default.png";
}
// Other Photos Code End
// Fashion Photos Code Start
if(isset($fashionPhotos)) {
if(!file_exists('uploads/models/fashionPhotos')) {
mkdir('uploads/models/fashionPhotos', 0777, true);
}
foreach($fashionPhotos as $fashionPhoto) {
$currentDate = Carbon::now()->toDateString();
$fashionPhotoName = $slug.'-'.$currentDate.'-'.uniqid().'.'.$fashionPhoto->getClientOriginalExtension();
$fashionPhoto = new FashionPhoto();
$fashionPhoto->our_models_id = $model->id;
$fashionPhoto->image = $fashionPhotoName;
Storage::disk('public')->put('uploads/models/fashionPhotos', $fashionPhotoName);
$fashionPhoto->save();
}
}else{
$fashionPhotoName = "default.png";
}
// Fashion Photos Code End
// Arabic Photos Code Start
if(isset($arabicPhotos)) {
if(!file_exists('uploads/models/arabicPhotos')) {
mkdir('uploads/models/arabicPhotos', 0777, true);
}
foreach($arabicPhotos as $arabicPhoto) {
$currentDate = Carbon::now()->toDateString();
$arabicPhotoName = $slug.'-'.$currentDate.'-'.uniqid().'.'.$arabicPhoto->getClientOriginalExtension();
$arabicPhoto = new ArabicPhoto();
$arabicPhoto->our_models_id = $model->id;
$arabicPhoto->image = $arabicPhotoName;
Storage::disk('public')->put('uploads/models/arabicPhotos', $arabicPhotoName);
$arabicPhoto->save();
}
}else{
$arabicPhotoName = "default.png";
}
// Arabic Photos Code End
return redirect()->route('ourmodels.index')->with('successMsg', 'Model Created !');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment