i am trying to first set in controller setOption(value, valuename) in controller and store in database and use it as getOption in views
but not working .
Here is my controller =>
public function edit(Request $request)
{
mpc_m_c($request->server('SERVER_NAME'));
$options = Config::all()->pluck('value','name');
$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
return view('admin.system-settings', compact('options', 'tzlist'));
}
public function update(Request $request)
{
$this->validate($request, [
'app_name' => 'required',
'currency_symbol' => 'required',
'currency_code' => 'required',
'date_format' => 'required',
'home_page_description' => 'required',
'recaptcha_private_key' => 'required',
'minimum_deposit_amount' => 'required',
'home_page_meta' => 'required',
'notify_email' => 'required'
]);
if ($request->hasFile('logo')) {
$file = $request->file('logo');
$fileArray = array('logo' => $file);
$rules = array(
'logo' => 'mimes:png|required|' // max 10000kb
);
$validator = Validator::make($fileArray, $rules);
if ($validator->fails()) {
$errors = $validator->errors()->getMessages();
return redirect()
->back()
->withErrors(['logo' => $errors['logo']]);
} else {
$logo = Storage::putFile('images', $request->file('logo'));
setOption('logo', $logo);
}
}
if ($request->hasFile('banner')) {
$file = $request->file('banner');
$fileArray = array('banner' => $file);
$rules = array(
'banner' => 'mimes:png,jpg,jpeg|required|' // max 10000kb
);
$validator = Validator::make($fileArray, $rules);
if ($validator->fails()) {
$errors = $validator->errors()->getMessages();
return redirect()
->back()
->withErrors(['banner' => $errors['banner']]);
} else {
$banner = Storage::putFile('images', $request->file('banner'));
setOption('banner', $banner);
}
}
setOption('app_name', $request->input('app_name'));
setOption('currency_symbol', $request->input('currency_symbol'));
setOption('currency_code', $request->input('currency_code'));
setOption('date_format', $request->input('date_format'));
setOption('home_page_description', $request->input('home_page_description'));
setOption('recaptcha_public_key', $request->input('recaptcha_public_key'));
setOption('recaptcha_private_key', $request->input('recaptcha_private_key'));
setOption('minimum_deposit_amount', $request->input('minimum_deposit_amount'));
setOption('home_page_meta', $request->input('home_page_meta'));
setOption('module_support_enabled', $request->input('module_support_enabled'));
setOption('module_api_enabled', $request->input('module_api_enabled'));
setOption('module_subscription_enabled', $request->input('module_subscription_enabled'));
setOption('theme_color', $request->input('theme_color'));
setOption('background_color', $request->input('background_color'));
setOption('language', $request->input('language'));
setOption('display_price_per', $request->input('display_price_per'));
setOption('admin_layout', $request->input('admin_layout'));
setOption('user_layout', $request->input('user_layout'));
setOption('panel_theme', $request->input('panel_theme'));
setOption('anonymizer', $request->input('anonymizer'));
setOption('front_page', $request->input('front_page'));
setOption('show_service_list_without_login', $request->input('show_service_list_without_login'));
setOption('notify_email', $request->input('notify_email'));
setOption('currency_separator', $request->input('currency_separator'));
setOption('timezone', $request->input('timezone'));
Session::flash('alert', __('messages.updated_logout_needed'));
Session::flash('alertClass', 'success');
return redirect('/admin/system/settings');
}
route =>
Route::get('/system/settings', 'ConfigController#edit');
Route::put('/system/settings', 'ConfigController#update');
error =>
"Call to undefined function App\Http\Controllers\Admin\setOption()"
and view =>
<div class="form-group{{ $errors->has('home_page_meta') ? ' has-error' : '' }}">
<label for="home_page_meta" class="control-label">meta tags</label>
<textarea
style="height: 150px;"
class="form-control"
data-validation="required"
rows="5"
id="home_page_meta"
name="home_page_meta"> <?php echo e($options['home_page_meta']) ?></textarea>
</div>
use =>
getOption('valuename')
And by this things he is using the function getOption(''valuename) anywhere in the entire application ... i really dont want use it but just curious How he is using this things even there's no laravel build in funtion for this name?
*Note : Please don't judge me , I just want to know ..thnaks
anybody got idea how do i use it ?
Related
I'm having problem that I would like to send Email with multiple images in Laravel9.
I wrote below code.
My goal is send Email with multiple images and
sametime each image file name stores into mysql's 'fileattach' column as photo1, photo2, photo3(one line)
Could someone correct my code please?
blade file
<div class="col-sm-6">
<input type="file" name="files[]" accept="file_extension|image/*|media_type" multiple>
</div>
Controller
public function saveContact(Request $request) {
$this->validate($request, [
'name' => 'required',
]);
if(count($files) > 0) {
foreach($files as $file) {
$message->attach($file->getRealPath(), array(
'as' => $file->getClientOriginalName(),custom name
'mime' => $file->getMimeType())
);
}
}
$contact = new Contact($request->all());
$contact->save();
\Mail::send('admin_email_tpl', //admin tpl
array(
'sno' => $request->get('sno'),
'name' => $request->get('name'),
'email' => $request->get('email'),
'files' => $request->post('files'),
), function($message) use ($request)
{
$message->from('123#123foobar.com');
$message->to('123#123foobar.com');
$message->subject('Thank You');
});
You are almost there, need to put the attachment code into callback method to mail.
public function saveContact(Request $request) {
$this->validate($request, [
'name' => 'required',
]);
//Get the $files array here
$files = [];
$contact = new Contact($request->all());
$contact->save();
\Mail::send('admin_email_tpl', //admin tpl
array(
'sno' => $request->get('sno'),
'name' => $request->get('name'),
'email' => $request->get('email'),
'files' => $request->post('files'),
), function($message) use ($request, $files)
{
$message->from('123#123foobar.com');
$message->to('123#123foobar.com');
$message->subject('Thank You');
if(count($files) > 0) {
foreach($files as $file) {
$message->attach($file->getRealPath(), array(
'as' => $file->getClientOriginalName(),//custom name
'mime' => $file->getMimeType())
);
}
}
});
}
i am new for laravel, i am not able to save the files in database on update function can any one help me for this,I have two related tables where one is a ticekt table and the other a one a documents table. In the documents table are the columns id, doc_name,doc_path,user_id and service_id. I'm trying to edit multiple images when editing a service. documents table not updating remaining things update successful
Cread service code
public function store(Request $request)
{
$rules = [
'email' => 'required|string|max:255',
'typeofservice' => 'required',
'companyname' => 'required',
'representative'=> 'required',
'phone' => 'required',
'services' => 'required',
'applicant' => 'required',
//'document' => 'required',
//'document.*' => 'required',
'remark' => 'required',
];
$validator = Validator::make($request->all(),$rules);
if($validator->fails()){
return back()->with('warning','please Fill manadatory fields');
} else {
//$dates = ;
//dd($dates);
$ticket = new Ticket([
'user_id' => Auth::user()->id,
'ticket_id' => strtoupper(str_random(10)),
'email'=>$request->input('email'),
'typeofservice' => $request->input('typeofservice'),
'companyname' => $request->input('companyname'),
'representative' => $request->input('representative'),
'phone' => $request->input('phone'),
'services' => $request->input('services'),
'applicant' => $request->input('applicant'),
'remark' => $request->input('remark'),
'ticket_submit_date' => date('d-M-Y'),
'status' => "1",
]);
//dd($ticket);
$ticket->save();
$userId = Auth::id();
$last_id = DB::getPdo()->lastInsertId();
if($ticket) {
if($request->hasfile('documents')) {
foreach($request->file('documents') as $doc)
{
$name = $doc->getClientOriginalName();
$destinationPath = 'public/documets/';
$documentPath = date('YmdHis') . "." . $doc->getClientOriginalExtension();
$doc->move($destinationPath, $documentPath);
Document::create([
'doc_name' => $name,
'doc_path' => $documentPath,
'user_id' => $userId,
'ser_id' => $last_id,
]);
}
}
//return $last_id;
$ticket_details = DB::table('ticket')->where('id','=',$last_id)->first();
$users = User::where('id','=',$ticket_details->user_id)->first();
$ticketid = $ticket_details->ticket_id;
$username = $users->first_name.' '.$users->last_name;
$mdata = ['ticketid'=>$ticketid,'name'=>$username];
$user['to']= $users->email;
Mail::send('emails.user_create_application',$mdata,function($message) use ($user){
$message->to($user['to']);
$message->subject('User Create Application');
});
return back()->with("success","Service Requiest Created Successfully! your tracking id:#$ticket->ticket_id" );
}
}
}
For uddate function given below
public function udateuserticket(Request $request, $id){
$rules = [
'email' => 'required|string|max:255',
'typeofservice' => 'required',
'companyname' => 'required',
'representative'=> 'required',
'phone' => 'required',
'services' => 'required',
'applicant' => 'required',
//'document' => 'required',
//'document.*' => 'required',
'remark' => 'required',
];
$email = $request->email;
$typeofservice = $request->typeofservice;
$companyname = $request->companyname;
$representative = $request->representative;
$phone = $request->phone;
$services = $request-> services;
$applicant = $request->applicant;
$remark = $request->remark;
$updateuserticket = Ticket::where('id','=',$id)->update([
'email' => $email,'typeofservice' =>$typeofservice, 'companyname' => $companyname, 'representative' => $representative,'phone' => $phone,'services' => $services, 'applicant' => $applicant, 'remark' => $remark ]);
$userId = Auth::id();
$last_id = DB::getPdo()->lastInsertId();
if($updateuserticket){
if($request->hasfile('documents')) {
foreach($request->file('documents') as $doc)
{
$name = $doc->getClientOriginalName();
$destinationPath = 'public/documets/';
if(File::exists($destinationPath)){
File::delete($destinationPath);
}
$documentPath = date('YmdHis') . "." . $doc->getClientOriginalExtension();
$doc->move($destinationPath, $documentPath);
Document::create([
'doc_name' => $name,
'doc_path' => $documentPath,
'user_id' => $userId,
'ser_id' => $last_id,
]);
}
}
$ticket_details = DB::table('ticket')->where('id','=',$last_id)->first();
//$users = User::where('id','=',$ticket_details->user_id)->first();
//$ticketid = $ticket_details->ticket_id;
//$username = $users->first_name.' '.$users->last_name;
return redirect('showtickets')->with('success','Ticket Updated Successfully!');
}
}
for view
#foreach( $documents as $doc )
<div class="col-md-6">
<input id="documents" type="file" class="form-control" name="documents[]" value="" required>
<img src="{{ url('/') }}/public/documets/{{ $doc->doc_path }}" alt="user-img" class="img-width" style="width:30px;height:30px;">
</div>
#endforeach
This one update only details not able to update documents can you please guid anyone where i am wrong
There are an error showing when i add #if ({{Auth::user()->utype}} == "ADM") Line of code in product.blade.php.
</head>
#if ({{Auth::user()->utype}} == "ADM")
<body>
</body>
#endif
This is my controller named ProductController.
public function index()
{
$products = Product::all();
return view('product', compact('products'));
}
public function create()
{
return view('product');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'brand' => 'required',
'detail' => 'required',
'size' => 'required',
'type' => 'required',
'price' => 'required',
'image' => 'required',
]);
$image = $request->file('image');
$new_name = rand().'.'.$image->getClientOriginalExtension();
$image->move(public_path('images'), $new_name);
$form_data = array(
'image' => $new_name,
'name' => $request->input('name'),
'size' => $request->input('size'),
'type' => $request->input('type'),
'price' => $request->input('price'),
'detail' => $request->input('detail'),
'brand' => $request->input('brand'),
);
Product::create($form_data);
return redirect()->route('product.index')->withSuccess('Done');
}
enter image description here
Please help me to solve the mistake.
You are already using blade directive, so no need to put {{}}, inside #if or any other directive try this
#if (Auth::user()->utype == "ADM")
<body>
</body>
#endif
how to save multiple selcet in laravel when I try the script below, not to save
this store in controller
public function store(Request $request)
{
$id = $request->id;
$post = Rek_medik::updateOrCreate(['id' => $id],
[
'kode_rekmed' => $request->kode_rekmed,
'kode_register' => $request->kode_register,
'kode_pasien' => $request->kode_pasien,
'nama_pemeriksa' => $request->nama_pemeriksa,
'tgl_rekmed' => Carbon::now(),
'anamnesis' => $request->anamnesis,
'pemeriksaan' => $request->pemeriksaan,
'resep' => $request->resep,
]);
return response()->json($post);
}
this is code in view
<div class="form-group">
<label for="resep">Resep</label>
<select class="select2bs4" id="resep" multiple="multiple" name="resep[]" data-placeholder="Select a State"
style="width: 100%;">
#foreach($obat as $row)
<option value="{{$row->kd_obat }}" >{{$row->kd_obat }}</option>
#endforeach
</select>
</div>
Why do not you try looping through your multiple select value and save the array's element: Like this : foreach($request->resep as $item){..then save your data here..}.
i think you should use 'save' function
public function store(Request $request)
{
$id = $request->id;
$post = Rek_medik::updateOrCreate(['id' => $id],
[
'kode_rekmed' => $request->kode_rekmed,
'kode_register' => $request->kode_register,
'kode_pasien' => $request->kode_pasien,
'nama_pemeriksa' => $request->nama_pemeriksa,
'tgl_rekmed' => Carbon::now(),
'anamnesis' => $request->anamnesis,
'pemeriksaan' => $request->pemeriksaan,
'resep' => $request->resep,
]);
$result = $post->save();
return response()->json($post);
}
Well, u can modify your array first before save it to database. I assume your resep column type is varchar. Here's my solution
$id = $request->id;
foreach($request->resep[] as $r){
$resep[] = $r;
}
$post = Rek_medik::updateOrCreate(['id' => $id],
[
'kode_rekmed' => $request->kode_rekmed,
'kode_register' => $request->kode_register,
'kode_pasien' => $request->kode_pasien,
'nama_pemeriksa' => $request->nama_pemeriksa,
'tgl_rekmed' => Carbon::now(),
'anamnesis' => $request->anamnesis,
'pemeriksaan' => $request->pemeriksaan,
'resep' => json_encode($resep),
]);
return response()->json($post);
json_encode function is to convert $resep array to string. You can change it back to array with json_decode function
json_decode($resep);
I am currently building a CRUD application using Laravel. It requires me to upload images and information but seems like there are some problems on storing the images to the localdisk folder.
Here is my controller code:
public function store(Request $request)
{
$lostitem =new Admin();
$this->validate($request, [
'date' => 'required',
'TimeFound' => 'required',
'AreaWhereFound' => 'required',
'image' => 'required',
'Remark' => 'required',
'DateClaimed' => 'required',
'TimeClaimed' => 'required',
'CategoryID'=>'required'
]);
$uuid = Str::uuid()->toString();
// $record = new Admin;
// return view('students.create');
$lostitem->code = $uuid;
$lostitem->date = $request->date;
$lostitem->TimeFound = $request->TimeFound;
$lostitem->AreaWhereFound = $request->AreaWhereFound;
$lostitem->image = $request->image;
if($request->hasfile('image'))
{
$filenameWithExt=$request->file('image')->getClientOriginalName();
$filename=pathinfo($filenameWithExt,PATHINFO_FILENAME);
$extension =$request->file('image')->getClientOriginalExtension();
$fileNameToStore=$filename.'_' .time().'.'.$extension;
$path=$request->file('image')->storeAs('public/images',$fileNameToStore);
// $file = $request->file('image');
// $extension =$file->getClientOriginalExtension();//getting image extensionimage
// $filename=time() ."." .$extension;
// $file->move('uploads',$filename->getClientOriginal);
// //getting from data base
}
else
{
// $lostitem->image = "";
$fileNameToStore='noimage.jpg';
}
$lostitem->image = $request->image ;
$lostitem->Remark = $request->Remark;
$lostitem->DateClaimed = $request->inputDateClaimed;
$lostitem->TimeClaimed = $request->TimeClaimed;
$lostitem->CategoryID = $request->CategoryID;
$lostitem->save();
return redirect(route('LostItem_add'))->with('successMsg', 'Record added!');
}
The other information is saved. I hope to get help.
Change Your controller code to this:
public function store(Request $request)
{
$lostitem =new Admin();
$this->validate($request, [
'date' => 'required',
'TimeFound' => 'required',
'AreaWhereFound' => 'required',
'image' => 'required',
'Remark' => 'required',
'DateClaimed' => 'required',
'TimeClaimed' => 'required',
'CategoryID'=>'required'
]);
$uuid = Str::uuid()->toString();
$lostitem->code = $uuid;
$lostitem->date = $request->date;
$lostitem->TimeFound = $request->TimeFound;
$lostitem->AreaWhereFound = $request->AreaWhereFound;
$lostitem->image = $request->image;
if($request->hasfile('image')){
$filenameWithExt=$request->file('image')->getClientOriginalName();
$filename=pathinfo($filenameWithExt,PATHINFO_FILENAME);
$extension =$request->file('image')->getClientOriginalExtension();
$fileNameToStore=$filename.'_' .time().'.'.$extension;
$path=$request->file('image')->move(public_path('images/'),$fileNameToStore);
}
else{
$fileNameToStore='noimage.jpg';
}
$lostitem->image = $request->image ;
$lostitem->Remark = $request->Remark;
$lostitem->DateClaimed = $request->inputDateClaimed;
$lostitem->TimeClaimed = $request->TimeClaimed;
$lostitem->CategoryID = $request->CategoryID;
$lostitem->save();
return redirect(route('LostItem_add'))->with('successMsg', 'Record added!');
}
And then access your image in the blade like this
<img src="{{ asset('images/'.$item->image) }}">
And make sure that you do have an folder named "images" in the public directory
Save the path of image in database
public function store(Request $request)
{
$lostitem =new Admin();
$this->validate($request, [
'date' => 'required',
'TimeFound' => 'required',
'AreaWhereFound' => 'required',
'image' => 'required',
'Remark' => 'required',
'DateClaimed' => 'required',
'TimeClaimed' => 'required',
'CategoryID'=>'required'
]);
$uuid = Str::uuid()->toString();
$lostitem->code = $uuid;
$lostitem->date = $request->date;
$lostitem->TimeFound = $request->TimeFound;
$lostitem->AreaWhereFound = $request->AreaWhereFound;
$lostitem->image = $request->image;
if($request->hasfile('image')){
$filenameWithExt=$request->file('image')->getClientOriginalName();
$filename=pathinfo($filenameWithExt,PATHINFO_FILENAME);
$extension =$request->file('image')->getClientOriginalExtension();
$fileNameToStore=$filename.'_' .time().'.'.$extension;
$path=$request->file('image')->move(public_path('images/'),$fileNameToStore);
}
else{
$fileNameToStore='noimage.jpg';
}
$lostitem->image = $path ;
$lostitem->Remark = $request->Remark;
$lostitem->DateClaimed = $request->inputDateClaimed;
$lostitem->TimeClaimed = $request->TimeClaimed;
$lostitem->CategoryID = $request->CategoryID;
$lostitem->save();
return redirect(route('LostItem_add'))->with('successMsg', 'Record added!');
}
& show it
<img src="{{ asset('images/'.$item->image) }}">