Category : laravel-8

I have a belongsToMany eloquent relationship between App/Models/User and App/Models/Role. The relationship between the user and the role is stored in role_user pivot table. I am trying to create an advanced search filter, which will display me the list of users under the specific role criteria. I have already done this for email criteria, i.e. ..

Read more

I have below code in Laravel Eloquent. InvoiceModel ::whereYear("invoiceDate", "=", 2000) ->select( ‘invoiceDate’, DB::raw(‘sum(totalPrice) as totalPrice’), DB::raw(‘sum(paid) as paid’), DB::raw(‘sum(balance) as balance’), DB::raw(‘sum(tax) as tax’) ) ->groupBy(DB::raw(‘Month(invoiceDate)’)) ->get(); below is the eloquent query in MySQL select `invoiceDate`, sum(totalPrice) as totalPrice, sum(paid) as paid, sum(balance) as balance, sum(tax) as tax from `tblinvoices` where year(`invoiceDate`) = 2000 ..

Read more

I’m working with Laravel 8 to develop my project and I have made two routes for my form: Route::get(‘profile/twoFactor’, [AppHttpControllersProfileController::class, ‘manageTwoFactor’])->name(‘profile.2fa.manage’); Route::post(‘profile/twofactor’, [AppHttpControllersProfileController::class, ‘postManageTwoFactor’]); And here is my form: <form method="POST" action=""> @csrf <div class="field select"> <select name="type"> <option value="off">OFF</option> <option value="sms">SMS</option> </select> </div></br> <div class="field"> <input type="phone" name="phone" placeholder="Phone number"> </div></br> <button class="BJadidBold">Send Code</button> ..

Read more

I am trying to display the error div below a certain field if the validation for that input failed along with the previous input on the designated field. Here’s my progress so far: in my controller file inside the store function (UserController > store): public function store(Request $request) { $validationRules = array( ‘first_name’ => ‘required|min:2|max:150’, ..

Read more

I know this question may sound stupid, but I’m working with Laravel, and I want to return an alert message for one of my route which is placed inside of a group route: Route::middleware(‘auth’)->group(function(){ Route::get(‘profile’, [AppHttpControllersProfileController::class, ‘index’])->name(‘profile’){ alert()->success(‘welcome’,’message’)->persistent(‘Ok’); } Route::get(‘profile/twofactor’, [AppHttpControllersProfileController::class, ‘manageTwoFactor’])->name(‘profile.2fa.manage’); Route::post(‘profile/twofactor’, [AppHttpControllersProfileController::class, ‘postManageTwoFactor’]); }); As you can see for the route profile I ..

Read more

I use Polymorphic Relationships of Laravel 8 to declare Models like following: Item: class Item extends Model { protected $table = ‘items’; public function costs() { return $this->belongsToMany(Receive::class, ‘cost_item’, ‘cost_id’, ‘item_id’) ->withPivot([ ‘id’, ‘cost_id’, ‘item_id’, ‘sku_id’, ‘qty’, ‘price’, ]) ->withTimestamps() ->using(CostItem::class); } } Movement: class Movement extends Model { protected $table = ‘movements’; public function ..

Read more

I have been able to deploy Laravel projects successfuly in the past. For the first time I am using Laravel 8 with Jetstream and Livewire. Laravel is now using Fortify for login and registration auth. My local server works perfect, no issues. After deploying the project to a Hostgator shared hosting account, my homepage loads ..

Read more

I’ve configured my web application to use database instead of file to store sessions. So far so good. I could store a pair of key value easily like this: $request->session()->put(‘current_page’, $request->route()->uri()); $request->session()->save(); Now I want to make an SQL query to retrieve all sessions which have the value users paired with current_page key and where ..

Read more

I am using Laravel Livewire and I need to include a vuejs component in the template. How can I bind vuejs list value in livewire? How to link/synchronize the values. Here are the fields. VueJs : <input name="cities" :value="selected"> Livewire : <input wire:model="cities" name="cities"> I have not something already done. I am looking for a ..

Read more

I want to shuffle and paginate data in laravel. when I use this code : `$questions = Question::where("exam_id",$exam->id)->shuffle()->paginate(1);` gives me this error : BadMethodCallException Call to undefined method IlluminateDatabaseEloquentBuilder::shuffle() and when I use this code: $questions = Question::where("exam_id",$exam->id)->paginate(1)->shuffle(); in dd($questions = Question::where("exam_id",$exam->id)->paginate(1)->shuffle());gives me a collection that has the first item and other items don’t exist. ..

Read more

i’m uploading my first laravel (v 8.x) project to cPanel and i got this error message PHP Fatal error: Uncaught RuntimeException: A facade root has not been set. in /home/billypom/laravel/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:258 Stack trace: #0 /home/billypom/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/RegisterErrorViewPaths.php(18): IlluminateSupportFacadesFacade::__callStatic(‘replaceNamespac…’, Array) #1 /home/billypom/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(563): IlluminateFoundationExceptionsRegisterErrorViewPaths->__invoke() #2 /home/billypom/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(544): IlluminateFoundationExceptionsHandler->registerErrorViewPaths() #3 /home/billypom/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(455): IlluminateFoundationExceptionsHandler->renderHttpException(Object(SymfonyComponentHttpKernelExceptionHttpException)) #4 /home/billypom/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Exce in /home/billypom/laravel/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 258 here is the ..

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

here i am sending array to getPostIMageArray function and getting new array merged with the old one, $newImageArray = $this->getPostImageArray($imageArray,$posts->id); $newVideoArray = $this->getPostVideoArray($videoArray,$posts->id); //updating the image field Upload::where(‘post_id’, $posts->id) ->update([ ‘image’=>($newImageArray!=[]) ? implode(‘ ‘, array_filter($newImageArray)) : null, ]); //getPostImageArray() function public function getPostImageArray($imageArray,$post_id){ $newImageArray=[]; $oldUploadJsonString=Upload::where(‘post_id’,$post_id)->get(‘image’); if(!empty($imageArray)){ foreach($imageArray as $image){ $newImageArray[] = $this->getPostImage($image); } if(!empty($oldUploadJsonString) || ..

Read more

here i am sending array to getPostIMageArray function and getting new array merged with the old one, $newImageArray = $this->getPostImageArray($imageArray,$posts->id); $newVideoArray = $this->getPostVideoArray($videoArray,$posts->id); //updating the image field Upload::where(‘post_id’, $posts->id) ->update([ ‘image’=>($newImageArray!=[]) ? implode(‘ ‘, array_filter($newImageArray)) : null, ]); //getPostImageArray() function public function getPostImageArray($imageArray,$post_id){ $newImageArray=[]; $oldUploadJsonString=Upload::where(‘post_id’,$post_id)->get(‘image’); if(!empty($imageArray)){ foreach($imageArray as $image){ $newImageArray[] = $this->getPostImage($image); } if(!empty($oldUploadJsonString) || ..

Read more