Category : laravel-controller

Background Let us consider a hypothetical scenario. Suppose we have five different tables in our database, Customers Categories Products Orders OderDetails Our client wants us to add a search bar to the frontend, where a user can search for a specific product and upon tapping the search button, matching products has to be displayed on ..

Read more

What I have blade.php file <form action="cars/{{ $car->id }}" method="POST" class="pt-3"> @csrf @method(‘delete’) <button type="submit" class="border-b-2 pb-2 border-dotted italc text-red-500" > Delete &rarr; </button> </form> Controller in Laravel public function destroy($id) { $car = Car::find($id)->first(); $car->delete(); return redirect(‘/cars’); } Problem The above controller, always deletes the record in the db that is one id behind. ..

Read more

I’m trying to redirect to an external URL from a helper class. Here’s my controller: <?php namespace AppHttpControllers; use AppLead; use IlluminateHttpRequest; use App; use Helper; class MyController extends Controller { public function entities_get() { Helper::my_function(); // <—- Call my Helper class method to redirect. return view( ‘template’ ); } } Here’s my helper class ..

Read more

i have 1 select image in my form which selects only one photo and my controller can only store one image address in database but i want to have 4 select image in my front which their’s all of name is image like this : <div class="image-upload-wrap"> <input class="file-upload-input" type=’file’ accept="image/*" name="image"/> <div class="drag-text"> <h5>Select</h5> ..

Read more

in the given picture which i am taking reference if route to login or register controller is working fine but in this scenario i am making my own app if i route in same method not working IlluminateContractsContainerBindingResolutionException: Target class [Productcontroller] does not exist. in file C:xampphtdocslaravelblogvendorlaravelframeworksrcIlluminateContainerContainer.php on line 875 this error pops up why? ..

Read more

I have tried to get the Auto Increment ID from the ‘booking’ table before saving the new data’s, but I have errors all the time when I try to find a way. This is the code in controller: function addAppointment(Request $request) { $user = auth()->user(); $booking = new Booking(); $booking->vac_center_id = $request->get(‘vaccination_center’); $booking->vac_id = $request->get(‘vaccination_id’); ..

Read more

I’m using laravel 8 and when i write route like this: web.php Route::match([‘get’, ‘post’], ‘/’, [PageController::class, ‘index’]); Route::match([‘get’, ‘post’], ‘/tshirt’, [PageController::class, ‘productCategory’]); Route::match([‘get’, ‘post’], ‘/electronic’, [PageController::class, ‘productCategory’]); Route::match([‘get’, ‘post’], ‘/tshirt/{slug}’, [PageController::class, ‘detail’]); Route::match([‘get’, ‘post’], ‘/electronic/{slug}’, [PageController::class, ‘detail’]); and controller like this: PageController.php <?php namespace AppHttpControllers; use IlluminateHttpRequest; class PageController extends Controller { public function index() ..

Read more

I have a function with the name of Direction which takes the request and redirects to the following view if the condition is true. here is the code public function direction(Request $request) { $activity_id=$request->id; $activity_type=Activity::where(‘id’,$activity_id)->pluck(‘type’); if($activity_type[0]==’event’) { return redirect()->route(‘getActivity’,compact(‘activity_id’)); } else{ echo "please select valid id "; } } it works perfectly, but I like ..

Read more

Am generating normal route for controller method, but it seems 404 error while using the route, other route is working but it fails while using edit route. i just print some msg in controller for testing purpose web.php use AppHttpControllersStudentController; use IlluminateSupportFacadesRoute; Route::get(‘/students’,[StudentController::class,’index’]);//this working Route::get(‘/students/{$student}/edit’,[StudentController::class,’edit’]);//this not working StudentController: … use AppModelsStudent; …. class StudentController extends ..

Read more

I am new to laravel and I am encountering this error IlluminateContractsContainerBindingResolutionException Target class [AppHttpControllerMpesaController] does not exist. http://127.0.0.1:8000/stk/push/simulation This is my controller class class MpesaController extends Controller { public function stkSimulation() { $TransactionType="CustomerPayBillOnline"; $Amount="1"; $CallBackURL="http://laravel-mpesa.test"; $AccountReference="Kevin’s Trial"; $TransactionDesc="Lipa na MPesa STK push"; $Remarks="Thank for paying!"; $stkPushSimulation=$mpesa->STKPushSimulation( $TransactionType, $Amount, $CallBackURL, $AccountReference, $TransactionDesc, $Remarks ); } ..

Read more

I have configured a resource route as below Route::resource(‘users’, UserController::class); When a user posts data, it will call the store method in the controller where it will add the data and set a message for success/failure. public function store(Request $request) { // return $request; $request->validate( [ "firstName" => ‘required’, "lastName" => ‘required’, "phoneNo" => ‘required’, ..

Read more

I want to get value change percentage from $userbalance change to $changebalance, I mean how much percentage change from 2500 to 2000? public function ChangeBalance() { $userbalance = ‘2500’; $changebalance = ‘2000’; $blchanges = $userbalance->changebalance/100; $data[‘blchanges’] = $blchanges; return view(‘dashboard’, $data); } Please help me with that. Sourc..

Read more

I have a query that work fine but does not work pagination how to convert into eloquent to apply pagination $projects=DB::select("select * from projects INNER JOIN(select DISTINCT * from (SELECT project_id FROM district_group_project_users where user_id=’$id’ UNION ALL select id from projects where created_by=’$id’) as sub ) as sub on sub.project_id=projects.id;"); OR is there any other ..

Read more

I have created an API that records records on the LoginActivity table anytime a user logs in. I want to the recorded activity to be only recorded once in 24hrs for every user. This is my activity_record.py model <?php namespace AppModels; use IlluminateDatabaseEloquentModel; class ActivityRecord extends Model { protected $fillable = [‘user_id’,’total_logins’, ‘is_active’]; public function ..

Read more

I am trying to store logged user’s id but I am getting this error ErrorException array_map(): Argument #2 should be an array This is the code in controller public function store(Request $request) { if (!auth()->check()) { abort(403, ‘Only authenticated users can create new posts.’); } $data = request()->validate([ ‘id’ => $id = Auth::id(), ‘content’ => ..

Read more

I have a problem when updating more images on share hosting but in my local machine everything is fine file_put_contents(/public/storage/article_image/post_162069532710.png): failed to open stream: No such file or directory This is my Update function $detail=$request->messageInput; $dom = new domdocument(‘1.0’, ‘UTF-8’); @$dom->loadHtml(‘<?xml encoding="UTF-8">’.$detail); libxml_use_internal_errors(true); $images = $dom->getelementsbytagname(‘img’); $bs64=’base64′;//variable to check the image is base64 or not ..

Read more

I’m designing a controller class for a production-level laravel project. This controller dictates what data is provided to the blade files (views). for one of the views, a function, getComponents() grabs and interprets a number of files for the view. decision This getComponents() function can either be declared as a class variable and provided to ..

Read more