Chris1989

Member Since 1 Month Ago

Experience Points
1,680
Total
Experience

3,320 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
4
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
1,680 XP
May
13
23 hours ago
Activity icon

Replied to Livewire Checkbox Optimization

The problem was something else with render, i dont know why but inserted on my task() function that i had other tasks thinks and i enter that code below:

public function tasks()
    {
        $customer = Customer::where('id', $this->customerID)->first();
       
        $this->hasnotify =$customer->hasnotify;

        return $this;

    }

Then i run the tasks on render and everything works

 return view('livewire.services.showservice', [
            'services' => $this->services,
            'tasks' => $this->tasks(),
            ])
```
Activity icon

Replied to Array To String Conversion Laravel Language Prefix

That is the exact error when i enter ['prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}']],

ErrorException
Array to string conversion
Activity icon

Replied to Eloquent Where Or Where Question

That was the latest try, the first set up was like i was close i think but also i saw the whereIn statement but i thought was only for numbers or ID's:

   $service = DB::table('services')
             ->where('customer_id', $this->customerID)
             ->where('service_type', 'type1')
             ->where('service_type', 'type2')
             ->latest()
             ->first();
Activity icon

Started a new Conversation Eloquent Where Or Where Question

I want to run a query to show Service data by latest date (that working) ONLY if the id = customer_id and service_type ='type1' OR service_type ='type2' in my case if i enter service_type -> 'type3' the query runs and show that type3 that i dont want. I tried with Orwhere but nothing work.

Service::where('customer_id',$this->customerID, function ($query) {
                $query->where('service_type','type1')
                       ->where('service_type','type2');
                        })->latest()->first();
Activity icon

Replied to Livewire Checkbox Optimization

It worked Sir, nice and clean, One notice, doesn't keep the Checked i want default will unsnecked and when i press so the value is 1 to keep the ckecked (tickbox)

Activity icon

Replied to Array To String Conversion Laravel Language Prefix

Array to string conversion error
May
12
1 day ago
Activity icon

Replied to Livewire Checkbox Optimization

The project its fast even on a shared host i dont have problem with speeds with livewire projects, it runs one query without foreach its a single button that takes value 0 or 1 , my problem is why must press double the button to check the box. See the example

https://imgur.com/l6kVATd

Activity icon

Started a new Conversation Array To String Conversion Laravel Language Prefix

Hi im trying to add Multi Language On laravel livewire Project, but i notice that when i change page doesnt keep the selected language so i foundthat must have a prefix on middleware, I followed some instructions and i made that setup on web.php and get the error:


Route::group(
['prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}']],
['middleware' => ['auth','isAdmin',]],

function () {

    Route::get('/dashboard', function () {
        return redirect('/customers');
    })->name('dashboard');

    Route::get('/customers', \App\Http\Livewire\Customers\Show::class)->name('showcustomers');
    Route::get('customer/{customerID}/services', \App\Http\Livewire\Services\ShowService::class)->name('showservice');
    Route::get('/users', \App\Http\Livewire\Users\Show::class)->name('showusers');

});
May
11
2 days ago
Activity icon

Started a new Conversation Livewire Checkbox Optimization

Any better idea how to improve that code of checkbox? because must press two times to unsnecked, and the code its too big

    @if ($customers->hasnotify == 1)
             <input type="checkbox" wire:click="hasnotify ({{ $customers->id }},0)"
                  class="form-checkbox h-5 w-5 text-green-600">

                 <span class="ml-2 text-gray-700">Remote Access</span>
                    @else
             <input type="checkbox" wire:click="hasnotify ({{ $customers->id }},1)"checked
                            class="form-checkbox h-5 w-5 text-green-600">

                        <span class="ml-2 text-gray-700">Remote Access</span>
                    @endif

The function that calls

  public function hasnotify($customerID, $action)
    {
       
      Customer::find($customerID)->update(['hasnotify' => $action]);
     
    }
Activity icon

Replied to Task Scheduler Run Once Locally

If i do that (schedule:run) i get error :

timeout: failed to run command ‘/usr/bin/php/home/myuser/domains/myurl.gr/public_html/mysubdomain/artisan’: Not a directory

I dont know about the public_html was from default settings, notice that im run on subdomain of a url.

Activity icon

Replied to Task Scheduler Run Once Locally

Can you give me an example please ? because i cant make it work, The latest settings from Hostinger support is that cron job :

* ----- ----- ----- -----	/bin/sh /home/myuser/domains/mysite.gr/public_html/e-mysubdomain/bash.sh

and the bash.sh

#!/bin/sh
/usr/bin/php /home/myuser/domains/mysite.gr/public_html/mysubdomain/artisan schedule:work 1>> /dev/null 2>&1

Kernel.php

 protected function schedule(Schedule $schedule)
    {
         $schedule->command('minute:update')->everyMinute();
   	
        // $schedule->command('check:reserve')->everyMinute();

    }

I made some changes like artisan schedule:run on bash.sh but no luck , or tried on kernel inside project to change to $schedule->command('check:reserve')->everyMinute(); but nothing,.. The support tolds me that the paths are correct. so maybe is something else,

May
10
3 days ago
Activity icon

Replied to Task Scheduler Run Once Locally

Im using Hostinger that has already Cron Jobs

I see one archive on ftp .logs like cronjob_xCRJYdmceS and is empty.

Activity icon

Replied to Task Scheduler Run Once Locally

I change the bash.sh to

* * * * * php -q /home/myuser/domains/mysite.gr/public_html/mysubdomain/artisan schedule:run 1>> /dev/null 2>&1

I create a cron Job :

bash /home/myuser/domains/mysite.gr/public_html/mysubdomain/bash.sh	

But no luck on Host.

Activity icon

Replied to Task Scheduler Run Once Locally

On the local Enviroment on visual studio if i make php artisan schedule:work finally Working! triggering every minute the action : output:


[2021-05-10T16:25:00+03:00] Execution #1 output:
Running scheduled command: "C:\xampp\php\php.exe" "artisan" minute:update > "NUL" 2>&1

[2021-05-10T16:26:00+03:00] Execution #2 output:
Running scheduled command: "C:\xampp\php\php.exe" "artisan" minute:update > "NUL" 2>&1

[2021-05-10T16:27:00+03:00] Execution #3 output:
Running scheduled command: "C:\xampp\php\php.exe" "artisan" minute:update > "NUL" 2>&1

can i use the same on the shared host ? or its different ?

Activity icon

Replied to Task Scheduler Run Once Locally

Unfortunately doesn't work event Once with that command, only with php artisan schedule:run , but still cant find why run once.

Activity icon

Started a new Conversation Task Scheduler Run Once Locally

Hi can you help me with a solution because i searched few topics about task scheduler but on my PC locally runs only once!, i followed that instructions https://www.jdsoftvera.com/how-to-add-laravel-task-schedule-on-windows/

and my project has that settings :

MinuteUpdate.php

    public function handle()
    {

        $users = User::all();

        foreach ($users as $user) {
           
                Mail::to($user->email)->send(new CrendentialsNotify($user->name,$user->email,$user->plate));
                $this->info('Minute Update');
         
        }
    }

Kernel.php

  protected function schedule(Schedule $schedule)
    {
        $schedule->command('minute:update')->everyMinute();
   
        // $schedule->command('check:reserve')->everyMinute();

    }

On Windows task library i see that last run time is correct(every 5 minutes) but the last time run doesnt refresh because doesnt trigger the task.. only i can see the first time that i run the task with that command> C:\xampp\htdocs\projects\laravel\myproject\artisan schedule:run

Also i tried to make it work on shared server using Cron that is more important to me , the support tolds me that must have a bash.sh to trigger the event the i create bash.sh on the subdomain folder i put that command inside:

 php -q /home/myuser/domains/mysite.gr/public_html/mysubdomain/artisan schedule:run 1>> /dev/null 2>&1

and run a custom cron

bash /home/myuser/domains/mysite.gr/public_html/mysubdomain/bash.sh	

But don't run nor one time! The support tolds me that the script is correct

May
05
1 week ago
Activity icon

Replied to Simple Pdf Export On Data Table

I tried but seems that doesn't recognize variables on blade with that setup i get error Undefined variable: customerId i don't know if must follow different approach, simply i for the moment i want the full data of customers to export on pdf

  public function generatePDF()
    {
        $customers = Customer::query()
        ->search($this->search, )
        ->withCount('services')
        ->orderBy($this->sortBy, $this->sortDirection, )
        ->paginate($this->perPage, );

  
        $pdf =PDF::loadview('livewire.customers.show', ['customers' => $customers,])
        ->extends('layouts.maindashboard')
        ->section('content');
        
        return $pdf->download('demo1.pdf');
            
    }
May
04
1 week ago
Activity icon

Started a new Conversation Simple Pdf Export On Data Table

Hi i want to download all data of a customer table when i click the download button but doesn't work, i get error Method Illuminate\Database\Eloquent\Collection::Total does not exist.

I think the problem is related with different settings of render function, but simply want to get all data of customer nothing else.


    public function generatePDF()
    {
        $customers = Customer::all();
        $pdf =PDF::loadview('livewire.customers.show',compact('customers'));
        return $pdf->download('demo1.pdf');
            
    }

Render Function

    public function render()
    { 

        $customers = Customer::query()
            ->search($this->search, ['id', 'name', 'plate'])
            ->withCount('services')
            ->orderBy($this->sortBy, $this->sortDirection, )
            ->paginate($this->perPage, );

        return view('livewire.customers.show', ['customers' => $customers,])
            ->extends('layouts.maindashboard')
            ->section('content');
    }
May
01
1 week ago
Activity icon

Replied to Redirect After Login According To User Role Laravel Fortify

Hi i have the same problem , i want on admin to access on /customers and on user on /services but i get error when apply that on wep.php

Route::group(['middleware' => [
    'auth:sanctum',
    'verified',
    'accessrole',

]], function () {
  
    Route::get('/dashboard', function () {
        if (!Auth::check()) {
            return redirect()->route('login');
        }

     
        if (in_array(Auth::user()->role, ['user'])) {
            return  redirect('/services')->name('showservices');;
        }
      
        return redirect('/customers')->name('dashboard');

    });

With that setup , when the role is user , still try to find /dashboard doesn't redirect to /services also i tried to make extra setting on redirecticauthedicated.php but still dont work properly


 public function handle(Request $request, Closure $next, ...$guards)
    {
        $guards = empty($guards) ? [null] : $guards;

        foreach ($guards as $guard) {
            if (Auth::guard($guard)->check() &&  (Auth::user()->role == 'admin')) 
            {
                return redirect(RouteServiceProvider::HOME);
            }
            else{

                Route::get('/', function () {
                    return redirect('/services');
                });
            
            }
        
        }

        return $next($request);
    }
Apr
28
2 weeks ago
Activity icon

Replied to Query Foreign Key

Yes, it was so simple.. Thank you very much

Activity icon

Replied to Query Foreign Key

i tried something like this, after your first post

 $charges = charge::query()
            ->search($this->search)
         ->select(\DB::raw('charges.*,SUM(taskscharges - payment) as balance','customers.name as custname'))

         ->join('customers', 'charges.customer_id', '=', 'customers.id')
            ->groupBy('id')
            ->orderBy($this->sortBy, $this->sortDirection)
            ->paginate($this->perPage);

I tried to sort the custname but i get error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'custname' in 'order clause' (SQL: select charges.*,SUM(taskscharges - payment) as balance from `charges` inner join `customers` on `charges`.`customer_id` = `customers`.`id` where (exists (select * from `users` where `charges`.`user_id` = `users`.`id` and (`tasks` like %% or `name` like %%)) or exists (select * from `customers` where `charges`.`customer_id` = `customers`.`id` and `name` LIKE %%)) group by `id` order by `custname` asc

I want to name it to use for sorting

Activity icon

Started a new Conversation Query Foreign Key

Hi i have two tables charges and customers(foreign) is it possible to make additional select to for table customers to get name ? as you can see inserted the join(commented) but cant find the way to make second select on the same query, i get error.

the query

 $charges = charge::query()
            ->search($this->search)

         ->select(\DB::raw('charges.*,SUM(taskscharges - payment) as balance'))
  
            // ->join('customers', 'charges.customer_id', '=', 'customers.id')
            ->groupBy('id')
            ->orderBy($this->sortBy, $this->sortDirection)
            ->paginate($this->perPage);
Apr
22
3 weeks ago
Activity icon

Replied to Laravel-Livewire Project With Shared Server Issues

I agree for the issues, although i have two working projects and has <60ms on that shared host , also for that simple projects or an simple website, its overkill to have a vps? why? to pay for a year more that 150 euro for 40gb? or to see some ms difference of speed that for Customer there even not noticeable ?

Activity icon

Started a new Conversation Laravel-Livewire Project With Shared Server Issues

Hi Im faced again a strange problem while uploading lavarel-livewire project on shared server (hostinger)

The project is on subdomain public-html/office The files of public are inside public-html/office and the other files are inside public-html/office/laravel folder

in office/index.php i changed that paths

 require __DIR__.'/laravel/vendor/autoload.php';

 $app = require_once __DIR__.'/laravel/bootstrap/app.php';

I deleted config file inside bootstrap cache, I inserted the correct credentials for sql (i tested locally and works) ( i tried "" on crendentials) I published the livewire assets I cleared all cache , optimize, etc before upload the project

And after that when i enter the site at the top of the page on fortify login page i get error

Connection failed: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

and the more bizarre is that can enter on project can see the all the db entries BUT seems like doenst load the livewire components, js scripts even tailwind css nothing working search,buttons,sortings, notging!

also on console i get a ton of errors

Uncaught SyntaxError: Unexpected identifier
livewire.js?id=ef0c4e092e24439bb958:1 Uncaught SyntaxError: Unexpected identifier
customers:1180 Uncaught ReferenceError: Livewire is not defined
    
(anonymous) @ customers:1180
customers:1209 Uncaught ReferenceError: PhpDebugBar is not defined
    at customers:1209

Notice that on Local machine everything works perfect! I think that something wrong with path that loads the components, have you ever seen that ?

Apr
20
3 weeks ago
Activity icon

Replied to Total Sum Of Select

Maybe i didn't explain very well, but the result is that working now, as i said i wanted only the sum of TOTAL balance property of balances, I want that queries to run outside of render query,Thats why i created total_balance and total_tasks function, So i merged and renamed to Tasks function and want if it possible to define and call that to fill the blade with that data iwant fill exact that metrics , https://imgur.com/SRoFYeD , the total_balance and the tasks,

Activity icon

Replied to Total Sum Of Select

Yes it worked! that exactly i want , to recognize the balance as balance property,

I make Sum('balance') and finally i get the total balance,

one last think , i inserted that to the previous function is it possible to have to returns or whaterver is it and call it on blade like > taks->total_tasks and tasks->total_balance? as you can see i commented the first return ,

Now i have on render : return view('livewire.customers.show',['customers' => $customers],['tasks' => $this->tasks()])

and on blade call the $tasks, how can i define the first return or the second return to show?

above the function :

 public function tasks()
    {          

     //return charge::where('success', 0)->count();

      $chargesSubQuery = Charge::selectRaw('customer_id, SUM(taskscharges - payment) as balance')
      ->groupBy('customer_id');
  
      return Customer::query()
      ->select('customers.*', 'balances.balance')
      ->joinSub($chargesSubQuery, 'balances', fn ($join) => $join->on('customers.id', '=', 'balances.customer_id'))
      ->sum('balance');
  
    }
Activity icon

Replied to Total Sum Of Select

Its little complicated , i tried to run query with the exact way that im running on render to collect the sum of each raw but and summarize to one but the 'balance' doesn't recognize as field , its a result of two fields ,to sum that balance,

on render have this :

  $customers = Customer::query()
     
            ->search($this->search)

             ->selectRaw('*, (select SUM(taskscharges) from `charges` where `customers`.`id` = `charges`.`customer_id`) - (select SUM(payment) from `charges` where `customers`.`id` = `charges`.`customer_id`) as balance')
            ->withSum('charges as total_charges', 'taskscharges')
             ->withSum('charges as total_payments', 'payment')
  			 ->orderBy($this->sortBy, $this->sortDirection)
             ->paginate($this->perPage);
Activity icon

Replied to Total Sum Of Select

Yes, each raw of that difference is named as balance and is grouped by customer, so i want the whole sum of that list of customers balance

Activity icon

Replied to Total Sum Of Select

Of course i followed your advice simply its different function than yours that is above :

public function total_count()
{
	return charge::where('success', 0)->count();
}

On new function i tried without collection but cant make it work, simply i want the sum of that balance field https://imgur.com/Epu37ZL the balance field is result of the query that i wrote inside total_balance Function

Also its a bit dirty to call function each query tasks is there any way to insert that two total_count and total_balance in one function and call with keys ? because the Render is with that way getting bigger and bigger

return view('livewire.customers.show',['customers' => $customers],['total_tasks' => $this->total_tasks()],['total_balance' => $this->total_balance()]) 
Activity icon

Started a new Conversation Total Sum Of Select

Hi im trying to summarize that query but im getting error the query is substract of two sums , and name it as balance for each raw, so i want the total sum of balance of all raws

 public function total_balance(){
        $collection = customer::get();
        $total_balance = $collection->selectRaw('*, (select SUM(taskscharges) from `charges` where `customers`.`id` = `charges`.`customer_id`) - (select SUM(payment) from `charges` where `customers`.`id` = `charges`.`customer_id`) as balance')->sum();
      
       return $total_balance;
          
}

Apr
19
3 weeks ago
Activity icon

Replied to Collections

Both are the best answers but only one can i choose , sry for that, Can i ask something else, can i insert second count for example $othertask= $collection->...... even from another table, and how can i return both of the and render on blade?

Because for now i return ['total_count' => $this->total_count()] on blade how can i define that total_count is for task 1 and total_coun for task 2?

Activity icon

Started a new Conversation Collections

Hi, I want to count the success field that is '0' value with collection

    public function total_count()
    {
        $collection = charge::get();
        
            return $collection->map(function ($charge) {
            $charge = $charge->whereSuccess('0')->count();
            return $charge;
            
        });
    }

I call the function like this on render (livewire)

 return view('livewire.customers.show', ['customers' => $customers],['total_count' => $this->total_count()],)

but on the blade view im getting result like :19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19

Instead of single Count number. I want a single number that is correctly 19.

Apr
18
3 weeks ago
Activity icon

Replied to Eloquent Computed Attributes

Im using livewire and i have on Render , the customers and charges are already binded with relation on models. can you give me please an example how to reach on the blade that data?

 public function render()
    {

            $customers = Customer::query()
 
            ->search($this->search)

            ->withSum('charges as total_charges', 'taskscharges')
            ->withSum('charges as total_payments', 'payment')
        
           
            ->withCount('charges')

            ->orderBy($this->sortBy, $this->sortDirection)
            ->paginate($this->perPage);

        return view('livewire.customers.show', ['customer' => $customers])

            ->extends('layouts.maindashboard')
            ->section('content');
    }
Activity icon

Started a new Conversation Eloquent Computed Attributes

Hi i saw few examples of computed attributes, i tried to make some attributes like this-> in Customer Model

   public function gettotal_successAttribute() {
      return $this->withSum('*, (select SUM(taskscharges) from `charges` where `customers`.`id` = `charges`.`customer_id`) - (select SUM(payment) from `charges` where `customers`.`id` = `charges`.`customer_id`) as balance');
      
  }

I tried to call with {{dd($customer->total_success)}} on my blade but i get errorTrying to get property 'total_success' of non-object

Why happened this?

Apr
14
4 weeks ago
Activity icon

Replied to Laravel Livewire Sorting Foreign Fields

We have good news, with 'dirty' option exact this it works!!:

->selectRaw('*, (select SUM(taskscharges) from `charges` where `customers`.`id` = `charges`.`customer_id`) - (select SUM(payment) from `charges` where `customers`.`id` = `charges`.`customer_id`) as balance')
       
        ->withSum('charges as total_charges','taskscharges')
        ->withSum('charges as total_payments','payment')

With the second option :

->withSum('charges as total_charges','taskscharges')
->withSum('charges as total_payments','payment')
 ->selectRaw('*, total_charges - total_payments as balance')

I get syntax error

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '*, total_charges - total_payments as balance, 

For sure the second option is clearer but i dont have problem if works the first...

Activity icon

Replied to Laravel Livewire Sorting Foreign Fields

Still get the same error , i tried with

->selectRaw('*, SUM(charges.taskscharges) - SUM(charges.payment) as balance')

and

 ->selectRaw('*, SUM(charges.taskscharges) - SUM(charges.payment) as balance')->with('charge')

as i see from the error the ->with() doesnt work, must insert the relation on query with some way

Activity icon

Replied to Laravel Livewire Sorting Foreign Fields

Yes the taskscharges and the payment are the columns of charges table you can look the schema :

Schema::create('charges', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('customer_id');
            $table->unsignedBigInteger('user_id');
            $table->string('tasks');
            $table->string('taskscharges')->nullable();
            $table->string('payment')->nullable();
            $table->date('payment_date')->nullable()->default(null)->change();
            $table->text('comments')->nullable();
            $table->tinyInteger('success')->default('1');
Activity icon

Replied to Laravel Livewire Sorting Foreign Fields

Tried to call with the function ->with() but seems not recognize it, i get error :

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'taskscharges' in 'field list' (SQL: select *, SUM(taskscharges) - SUM(payment) as balance, (select count(*) from `charges` where `customers`.`id` = `charges`.`customer_id`) as `charges_count` from `customers` where (`name` like %% or `vat` like %%) order by `name` asc limit 20 offset 0)

The query :

 $customers = Customer::query()
       ->search($this->search)

       ->selectRaw('*, SUM(taskscharges) - SUM(payment) as balance')->with('charges')
 	   ->withSum('charges as total_charges','taskscharges')
       ->withSum('charges as total_payments','payment')

       ->withCount('charges')  
       ->orderBy($this->sortBy,$this->sortDirection)
       ->paginate($this->perPage);
Apr
13
1 month ago
Activity icon

Replied to Laravel Livewire Sorting Foreign Fields

Must i use collections for that?

Activity icon

Started a new Conversation Laravel Livewire Sorting Foreign Fields

Hi i have two tables customers and charges I want to sort the third field that will be balance on customers foreach blade,

as you can see i comment out the ->selectRaw('*, total_charges - total_payments as balance',) Because i get error that fields > total_charges and total_payments is Sum of the foreign table , so is any simple way to recognize as balance to make the sort?

My blade :

 <th  wire:click="sortBy('total_charges')" >Charge </th>
                           
   <th wire:click="sortBy('total_payments')" >Payments</th>
                           
  <th wire:click="sortBy('services_count')">balance</th>

 <td>{{ $customer->total_charges}}&euro; </td>
 <td>{{ $customer->total_payments}}&euro;</td>
 <td>{{ $customer->total_payments - $customer->total_charges}}&euro;</td>

Component:

 public function render()
    {
        $customers = Customer::query()
       ->search($this->search)
       //->selectRaw('*, total_charges - total_payments as balance',)
       ->withSum('charges as total_charges','taskscharges')
       ->withSum('charges as total_payments','payment')
       
       ->withCount('charges')  
       ->orderBy($this->sortBy,$this->sortDirection)
       ->paginate($this->perPage);
 

        return view('livewire.customers.show',['customers'=>$customers 
        ])
        ->extends('layouts.maindashboard')
        ->section('content');
    }
Apr
12
1 month ago
Activity icon

Replied to Eloquent Search From Two Foreign Tables

It worked thank you very much!

Apr
11
1 month ago
Activity icon

Started a new Conversation Eloquent Search From Two Foreign Tables

Hi i have a problem with my search query, im trying to search charges->tasks (main table) , customer->name , user->name (foreigns) the charegs->tasks and user->name filtering data on my search, the customer->name doesnt filtering and i cant make it work, did you see something wrong with the code?

The code:

    public function scopeSearch($query, $val){
        return $query->has('customer')
            ->whereHas('user', function($query) use ($val) {
                $query->where('tasks','like','%'.$val.'%')
                    ->Orwhere('name','like','%'.$val.'%');
                     })
           ->whereHas('customer', function($query) use ($val)
        {
            $query->orwhere('name', 'LIKE', '%'.$val.'%');
        })
        
           ->with('user')
           ->with('customer');
    }

The debugbar output:

select count(*) as aggregate from `charges` where exists (select * from `customers` where `charges`.`customer_id` = `customers`.`id`) and exists (select * from `users` where `charges`.`user_id` = `users`.`id` and (`tasks` like '%vas%' or `name` like '%vas%')) and exists (select * from `customers` where `charges`.`customer_id` = `customers`.`id` or (`name` LIKE '%vas%'))
Apr
10
1 month ago
Activity icon

Replied to Lifecycle Hooks Question

Any solution for that??

Apr
08
1 month ago
Activity icon

Replied to Is It Possible To Run Simultaneously Bootstrap And Tailwind On Laravel?

I agree , i want to make clean code, But unfortunately i cant work without Jetstream, so is there any video with tailwind dashboard setup?

Activity icon

Started a new Conversation Is It Possible To Run Simultaneously Bootstrap And Tailwind On Laravel?

I wan to have a Clean assets on my code and i choose to make a fresh start ,

I make new laravel installation,

  1. composer create-project laravel/laravel example-app
  2. composer require laravel/ui
  3. php artisan ui bootstrap
  4. npm install && run dev
  5. installed via composer admin-lte
  6. i made all requirements-imports about bootstrap.js and sass/app.scss

The templates runs smooth , But i want Livewire with Jetstream + auth when i installed the bootstrap deleting the scss folder disappearing and the whole webpack.mix.js delete everything about bootstap, when i run again the php artisan ui bootstrap , the files recovering but im running in error on npm run dev

Is there any way to runs both whats the correct sequent?

otherwise is there any similar admin dashboard where easy to install on tailwinds?

Please help me i made over 5 failed setups :/

Activity icon

Started a new Conversation Lifecycle Hooks Question

Hi im trying to make work two Updated() functions simultaneously is it possible? Simply i have a modal form that listening for errors and also want on spesific field (Plate) to auto Upper the value,

that works only if i comment the main function Updated on both.

also is it possible to make it little faster the check validation?

 public function updated($propertyName)
    {
        $this->validateOnly($propertyName);
   }

    public function updatedPlate($value)
     {  
        $this->plate=$value;
     }


     public function upper($value){
     
        $process = strtoupper($value);
      
        $this->plate=$process;
       
     }

Activity icon

Replied to LiveWire Live Actions Question

Ohh my!!! I forgot to remove that from the tons of changes that i made! now its working!!!! thank you very much all for help!!!

Activity icon

Replied to LiveWire Live Actions Question

What else can i use? must have button with relative Row id to know which row must update the function..

Activity icon

Replied to LiveWire Live Actions Question

Why is that too complicated? I dont know but i reach to successfully change the values with more simple way ,But im facing an error that i dont know why , look the gif : https://prnt.sc/117exh1

and the code that updates the value:


public function success($serviceID,$action)
{    
    service::find($serviceID)->update(['success'  => $action]);
   
}

my blade (its table with foreach):

 <td wire:click="success({{ $service->id }})" class="border px-4 py-2  cursor-pointer"> 
                                                
 @if  ($service->success == 1)
      <span wire:click="success ({{ $service->id }},0)" class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800"> Success </span>
 @else
      <span wire:click="success ({{ $service->id }},1)"  class="px-2 inline-flex text-xs leading-5 font-semibold 
      rounded-full bg-red-100 text-red-800"> Not Success </span> 
 @endif
                                            </td>