Category : php

I would like to pass the two variables between two functions in one controller here is my code Web.php file Route::get(‘reports/export’,’[email protected]’)->name(‘exportPDF’); Route::post(‘reports/viewFilter’,’[email protected]’)->name(‘viewFilter’); here is the controller both functions public function viewFilter(Request $request) { $camp_id=$request->camp_id; $school_level=$request->school_level; $school_shift=$request->school_shift; $school_type=$request->school_type; if($request->has(‘camp_id’) && !empty($request->input(‘camp_id’))||$request->has(‘school_level’) && !empty($request->input(‘school_level’))||$request->has(‘school_type’) && !empty($request->input(‘school_type’))||$request->has(‘school_shift’) && !empty($request->input(‘school_shift’))) $schools=School::where(‘camp_id’,$camp_id) ->orWhere(‘school_level’,$school_level) ->orWhere(‘school_type’,$school_type) ->orWhere(‘school_shift’,$school_shift) ->get(); else $schools=School::where(‘school_active’,’Active’); // Here ..

Read more

I am filtering my products by colors in my Laravel 8 application. And I want to send a get request. Here are my colors <label class="w-full flex items-center space-x-2"> <span> <input type="checkbox" onChange="this.form.submit()" name="colors[]" value="{{$color->id}}" @if(in_array($color->id, $selectedColors)) checked @endif /> </span> <span class="block -mt-1 select-none"> {{$color->title}}</span> </label> Now the result I am getting from this ..

Read more

I have some problems with authentication users with my API. I have installed Passport and I’m trying to return json object if user is not authenticated. I have created middleware that looks like: use IlluminateSupportFacadesAuth; class UserAuth { public function handle($request, Closure $next) { if(!Auth::check()){ return response()->json([‘response’ => false, ‘status’ => 403, ‘message’ => ‘Not ..

Read more

this is route Route::post(‘/delete/comment/{comment}’, ‘[email protected]’)->name(‘comment.delete’); this is function public function deleteAttachment(Comment $comment){ dd($comment); } and this is where I’m trying to use it <a target="_blank" class="btn btn-outline-danger function mr-2 " href="{{route(‘backend.ticket.comment.delete’,[‘comment’=>$comment->id])}}"><i class="mdi mdi-delete"></i></a> and this is error: The GET method is not supported for this route. Supported methods: POST. Sourc..

Read more

this is route Route::post(‘/delete/comment/{comment}’, ‘[email protected]’)->name(‘comment.delete’); this is function public function deleteAttachment(Comment $comment){ dd($comment); } and this is where I’m trying to use it <a target="_blank" class="btn btn-outline-danger function mr-2 " href="{{route(‘backend.ticket.comment.delete’,[‘comment’=>$comment->id])}}"><i class="mdi mdi-delete"></i></a> and this is error: The GET method is not supported for this route. Supported methods: POST. Sourc..

Read more

I asked to create a page that displays a list of all the categories and the last 3 products for each category. There is a relationship between the category and the products. Category Model: public function products(){ return $this->hasMany(‘AppModelsProduct’); } Product Model public function category(){ return $this->belongsTo(‘AppModelsCategory’); } Controller function that should return the result ..

Read more

Error Image here Login Route Route::get(‘/’, [HomeController::class, ‘index’]) ->name(‘index’) ->breadcrumbs(function (Trail $trail) { $trail->push(__(‘Home’), route(‘frontend.index’)); }); Authentication Routes Route::get(‘login’, [LoginController::class, ‘showLoginForm’])->name(‘login’); Route::post(‘login’, [LoginController::class, ‘login’]); Problem: My project is working fine when i run it locally but when i upload it on server it shows Method Not Allowed exception. I don’t know why. When i used ..

Read more

I want to make a new migration for my project, and this migration is called create_active_code.php and goes like this: public function up() { Schema::create(‘active_code’, function (Blueprint $table) { $table->bigIncrements(); $table->unsignedBigInteger(‘user_id’); $table->foreign(‘user_id’)->references(‘id’)->on(‘users’)->onDelete(‘cascade’); $table->integer(‘code’); $table->unique([‘user_id’, ‘code’]); $table->timestamps(‘expired_at’); }); } But as soon as I run this migration, I get this error: ArgumentCountError Too few arguments to ..

Read more

I am getting error Trying to access array offset on value of type int Below is my controller for storing array data into database for ($i = 1; $i < count($request->sanitation_point_id); $i++) { $sanitation_points[] = [ ‘daily_log_id’ => $daily_log->id[$i], ‘sanitation_point_id’ => $request->sanitation_point_id[$i] ]; SanitationDailylogRelation::create($sanitation_points); } Sourc..

Read more

I have a problem to add data or create data in my project laravel, how to solve it? i really confused for this this is the controller namespace AppHttpControllers; use AppModelsDaftarPelanggan; use IlluminateHttpRequest; use IlluminateHttpResponse; use IlluminateValidationRule; use IlluminateSupportFacadesValidator; use IlluminateSupportFacadesDB; use Alert; class DaftarPelangganController extends Controller { public function validator(Request $request) { return Validator::make($data, ..

Read more

I have a form like this: <form action="{{ route(‘profile.2fa.phone’) }}"> @csrf <div class="form-group"> <label for="token" class="col-form-label">Token</label> <input type="text" class="form-control @error(‘token’) is-invalid @enderror" name="token" placeholder="enter your token"> @error(‘token’) <span class="invalid-feedback"> <strong>{{ $message }}</strong> </span> @enderror </div> <div class="form-group"> <button class="btn btn-primary">Validate token</button> </div> </form> In this form, if the input field was empty this class="form-control @error(‘token’) ..

Read more

I want to use the WhereIn method in Eloquent but it now works like the below function. <?php $product = DB::table(‘product’) ->join(‘supplier’,’supp_code’,’=’,’prod_supplier_code’) ->select(‘product.*’,’supplier.supp_margin’) ->where(‘prod_seo_title’,’=’,$id) ->first(); $decArr = explode(‘,’,$product->prod_decoration_type); for($i=0; $i<count($decArr); $i++) { if($i==0) $inString = "’".$decArr[$i]."’,’"; elseif ($i<(count($decArr))-1) $inString .= $decArr[$i]."’,’"; else $inString .= $decArr[$i]."’"; } $proDeco = DB::table(‘decoration’)->whereIn(‘deco_print_type’, [$inString])->get(); ?> But In the query, ..

Read more

I have variable in foreach cos I want call data db to object, but if I put variable in compact is compact(): Undefined variable. here is my code of controller: public function schedule(Request $request, $id) { $data = Rusid::findOrFail($id); $tgl = Carbon::now()->format(‘Y-m-d’); $jam = Carbon::now()->format(‘h:i:s’); $queryData = "SELECT jam_selesai FROM `transaksi_view` where tanggal = CURDATE() ..

Read more