#### 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 ..

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 Laravel 8 with User & teamwork together I am working on data-table javascript, and controller but the error is still there, and it bugged me as I am not knowledgeable with laravel as I only work on laravel for one month (it’s perfect code and way better than WordPress PHP). I look at details on .. 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’); ..

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() ..

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 ..

i am new in Laravel and vue, i want to pass an int variable data from laravel controller to a vue component. Here is the controller, where i want to see the relation between user "3" and "1". if the follower 3 follows 1, the variable $foll=1, if not$foll=0 public function checkfollow($id) {$user ..

i was so confused about how to implement and how to follow the SRP (single responsibility principle ) in laravel controller suppose we have a controller which we have to do these things e.g public function StorePost(){ // check user login() //check number of current user Post count =>which must be less than 10 //store ..

I have an existing database which is already populated. I created a new column to store the month in which the data was populated. How do I populate the ‘month’ column with data based on the login_at at column of each row. I am able to populate the current inputs based on the current month ..

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’, ..

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 ..

Route::get(‘/{slug}/{id}/{product_slug}’, ‘[email protected]’)->name(‘view.image’); There is no problem with the font end page when using this route. But, why is Error showing on the back end page? Sourc..

I’m new to Laravel and I am trying to do a follow-unfollow system. I have tried to figure it out by myself for a week but I haven’t found any solution. I think I am doing wrong the SQL statement in the controller. This is the code in HomeController.php public function index() { $users = .. 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 ..

I have some problem with the controller. In my local repo as I serve the project it works! route: at web.php Route::get(‘/jobs’, ‘[email protected]’); But as I tried at my company’s server it didn’t work! It says controller does not exist. I’ve compared the controller and web route but it is the same with my local ..

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 ..