CliffordAtCaveoDotNL

CliffordAtCaveoDotNL

Lead Developer at Poortugaal

Member Since 4 Weeks Ago

Gouda

Experience Points
14,070
Total
Experience

930 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
78
Lessons
Completed
Best Reply Awards
9
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.

Level 3
14,070 XP
Mar
27
6 days ago
Activity icon

Replied to Has Many Relation

It is, look at the sql error:

Table 'restaurant.category_dish' doesn't exist

Activity icon

Replied to Has Many Relation

In your relation: category_dish

In your migration: category_dishes <- typo, should be category_dish

Activity icon

Replied to Laravel Getting Data From Two Tables

And what are the results?

Mar
26
1 week ago
Activity icon

Replied to Huge Array Data Duplication Checking Shows Execution Time Exceeded

What does your code look like when your are looking for duplicates?

Activity icon

Replied to Huge Array Data Duplication Checking Shows Execution Time Exceeded

Use distinct:

$contact_list = DB::table('sector_contacts AS c')
    ->distinct()
    ->leftJoin('sectors AS s', 'c.sector_id', '=', 's.id')
    ->select('s.id AS sector_id', 'c.id AS contact_id', 's.name AS sector_name', 's.dx_no AS dx_no', 'c.title AS contact_title', 'c.first_name AS first_name', 'c.last_name AS last_name', 'c.email AS email')
    ->where('c.sector_type', 1)
    ->get()
    ->toJson();
Activity icon

Replied to Huge Array Data Duplication Checking Shows Execution Time Exceeded

Which duplicates are you looking for and why not look/filter those through the query?

Activity icon

Replied to Laravel Getting Data From Two Tables

Have you tried my answer?

Activity icon

Replied to Datediff And Sum

What does your table structure looks like?

It think its because of the groepBy('id'), this (I guess) should be submitted_by.

Activity icon

Replied to "SQLSTATE[HY000]: General Error: 1364 Field 'images' Doesn't Have A Default Value (SQL: Insert Into `products` (`category_id`, `name_ar`, `name_en`, `shortDetail ▶"

Actually this whole section looks weird:

if($request->hasfile('images'))
        {

            foreach ($request->file('images') as $key => $value)
            {

                if ($products = $value)
                {
                    $destinationPath = 'public/files/'; // upload path
                    $fileName = date('YmdHis') . "." . $products->getClientOriginalExtension();
                    $products->move($destinationPath, $fileName);
                    $save[]['images'] = "$fileName";
                }
            }

        }

        Product::insert($save); // store file into mysql database

You are comparing an image with a product object and only saving a product with images later on.

Before this if statement you are creating and then saving the product.

Activity icon

Replied to Laravel Eloquent Problem

Change the orWhereIn to whereIn:

$tasks = Task::where('deleted_at', null)->where('status', 0)->whereIn('id', $task_ids);
Mar
25
1 week ago
Activity icon

Awarded Best Reply on Invoice No Increment

Try this:

$nextInvoiceNumber = $expNum[0].'-'. str_pad((int)$expNum[1]+1, 4, STR_PAD_LEFT);

Or even this:

$nextInvoiceNumber = 1;

$today = Carbon::today();

// Look for this years latest invoice.
$latestInvoice = Invoice::where('recp_no', 'like', $today->year.'-%')->latest()->first();

if ($latestInvoice) {
    // Get the number after the - and convert it to an int and increment with 1.
    $nextInvoiceNumber = (int) Str::after($latestInvoice->recp_no, '-') + 1;
}

$nextInvoiceNumber = $today->year.'-'.str_pad($nextInvoiceNumber, 4, STR_PAD_LEFT);
Activity icon

Replied to Laravel Getting Data From Two Tables

The use ($this->id) is the problem:

$referralContests = Contest::where([['type', '=', 'referral'], ['start_date', '>', $current_date]])->whereHas('contestDetail', function ($query) {
        $query->where('contest_id ', $this->id);
    })->get();
Activity icon

Replied to Laravel Eloquent With Multiple Where And OrWhere Clauses

Try grouping the where's for $cuisine:

$meals = Meals::select('*')
    ->selectRaw("( 6371 * acos( cos( radians({$latitude}) ) *
                                   cos( radians( latitude ) )
                                   * cos( radians( longitude ) - radians({$longitude})
                                   ) + sin( radians({$latitude}) ) *
                                   sin( radians( latitude ) ) )
                                 ) AS distance")
    ->where(static function ($query) use ($cuisine) {
        $query->where('cuisine', 'like', "%{$cuisine}%")
            ->orWhere('meal_name', 'like', "%{$cuisine}%");
    })
    ->where('country', '=' $country)
    ->where('blocked_seller', '=', 0)
    ->with('Meals_images')
    ->orderBy('distance', 'asc')
    ->get();
Activity icon

Awarded Best Reply on Laravel - Column Not Found Orders.user_id

I think you are missing the owner_id in the orders relationship.

public function orders() {
    return $this->hasMany(Order::class, 'owner_id');
}
Activity icon

Replied to Laravel - Column Not Found Orders.user_id

I think you are missing the owner_id in the orders relationship.

public function orders() {
    return $this->hasMany(Order::class, 'owner_id');
}
Activity icon

Replied to Invoice No Increment

Try this:

$nextInvoiceNumber = $expNum[0].'-'. str_pad((int)$expNum[1]+1, 4, STR_PAD_LEFT);

Or even this:

$nextInvoiceNumber = 1;

$today = Carbon::today();

// Look for this years latest invoice.
$latestInvoice = Invoice::where('recp_no', 'like', $today->year.'-%')->latest()->first();

if ($latestInvoice) {
    // Get the number after the - and convert it to an int and increment with 1.
    $nextInvoiceNumber = (int) Str::after($latestInvoice->recp_no, '-') + 1;
}

$nextInvoiceNumber = $today->year.'-'.str_pad($nextInvoiceNumber, 4, STR_PAD_LEFT);
Mar
24
1 week ago
Activity icon

Replied to Use Two Foreign Keys & Two Local Keys With HasMany Relation

Yes, course should be a relation on your Test model:

public function course()
{
    return $this->belongsTo(Course:class, 'course_id', 'id');
}

And the course hasMany questions:

class Course extends Model
{
    public function questions()
    {
        $this->hasMany(Question::class, 'course_id', 'course_id');
    }
}
Activity icon

Replied to Use Two Foreign Keys & Two Local Keys With HasMany Relation

Sorry I've overlooked something in your question but this might be the solution:

$questions = $test->course->questions()->where('subject_id', '=', $test->subject_id)->get();
Activity icon

Awarded Best Reply on Invalid Argument Supplied For Foreach()

You can remove this foreach:

@foreach($gallery->galleries as $c)

Your view would look like this:

@extends('Home.master')

@section('contents')
    <div class="bg-white">
        <div class="container">
            <h2 class="mb-5 mt-5">{{ $category->name }}</h2>
            <div class="row">
                @foreach($galleries as $gallery)
                    <div class="col-md-3 col-sm-6 col-12">
                        <div class="image_tn rounded border mb-2">
                            <a href="{{ asset('public/images/galleries/'.$gallery->image) }}" data-showsocial="true" data-thumbnail="{{ asset('public/images/galleries/'.$gallery->image) }}" class="html5lightbox" data-group="set1" data-width="800" data-height="600" title="{{ $gallery->title }}">
                                <img src="{{ asset('public/images/galleries/'.$gallery->image) }}" class="img-fluid d-block mx-auto rounded" alt="{{ $gallery->title }}"/>
                            </a>
                        </div>
                    </div>
                @endforeach
            </div>
        </div>
    </div>
@endsection
Activity icon

Awarded Best Reply on Users Email Field Nullable

You are correct about the validation:

/**
     * Validate the user login request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return void
     *
     * @throws \Illuminate\Validation\ValidationException
     */
    protected function validateLogin(Request $request)
    {
        $request->validate([
            $this->username() => 'required|string',
            'password' => 'required|string',
        ]);
    }

But if you want to be a 100% you can always extend the default guard to include something like:

->whereNotNull('email')
->whereNotNull('password')
Activity icon

Replied to Invalid Argument Supplied For Foreach()

You can remove this foreach:

@foreach($gallery->galleries as $c)

Your view would look like this:

@extends('Home.master')

@section('contents')
    <div class="bg-white">
        <div class="container">
            <h2 class="mb-5 mt-5">{{ $category->name }}</h2>
            <div class="row">
                @foreach($galleries as $gallery)
                    <div class="col-md-3 col-sm-6 col-12">
                        <div class="image_tn rounded border mb-2">
                            <a href="{{ asset('public/images/galleries/'.$gallery->image) }}" data-showsocial="true" data-thumbnail="{{ asset('public/images/galleries/'.$gallery->image) }}" class="html5lightbox" data-group="set1" data-width="800" data-height="600" title="{{ $gallery->title }}">
                                <img src="{{ asset('public/images/galleries/'.$gallery->image) }}" class="img-fluid d-block mx-auto rounded" alt="{{ $gallery->title }}"/>
                            </a>
                        </div>
                    </div>
                @endforeach
            </div>
        </div>
    </div>
@endsection
Activity icon

Replied to Users Email Field Nullable

You are correct about the validation:

/**
     * Validate the user login request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return void
     *
     * @throws \Illuminate\Validation\ValidationException
     */
    protected function validateLogin(Request $request)
    {
        $request->validate([
            $this->username() => 'required|string',
            'password' => 'required|string',
        ]);
    }

But if you want to be a 100% you can always extend the default guard to include something like:

->whereNotNull('email')
->whereNotNull('password')
Activity icon

Replied to Can't Seem To Do A Sum() On Results From A Groupby Results

In your PatientRecord model:

pubic function getTotalSellingPriceAttribute()
{
    return $this->prescriptions->sum(static function ($prescription) {
        return $prescription->medicine->selling_price;
    });
};

Then you can call it like this:

GH¢ {{ number_format($records->sum('total_selling_price'), 2) }}
Activity icon

Awarded Best Reply on Can't Seem To Do A Sum() On Results From A Groupby Results

Your sum should look something like this because of the groupBy in your controller, but as jlrdw says in this case you might be better off doing this in the query:

<div class="row mt-4 mb-5">
    @foreach ($groupedRecords as $key => $records)
        <div class="col-lg-4 col-md-12 col-sm-12 mb-2">
            <div class="card shadow payment-card">
                <div class="card-body">
                    <h6 class="card-title">
                        {{ $key }}
                    </h6>
                    <h5 class="font-weight-bold pt-3">
                        GH¢ {{ number_format(
$records->sum(static function ($record) {
    return $record->prescriptions->sum(static function ($prescription) {
        return $prescription->medicine->selling_price;
    });
}),
2) }}
                    </h5>
                </div>
            </div>
        </div>
    @endforeach
</div>
Activity icon

Replied to Can't Seem To Do A Sum() On Results From A Groupby Results

Your sum should look something like this because of the groupBy in your controller, but as jlrdw says in this case you might be better off doing this in the query:

<div class="row mt-4 mb-5">
    @foreach ($groupedRecords as $key => $records)
        <div class="col-lg-4 col-md-12 col-sm-12 mb-2">
            <div class="card shadow payment-card">
                <div class="card-body">
                    <h6 class="card-title">
                        {{ $key }}
                    </h6>
                    <h5 class="font-weight-bold pt-3">
                        GH¢ {{ number_format(
$records->sum(static function ($record) {
    return $record->prescriptions->sum(static function ($prescription) {
        return $prescription->medicine->selling_price;
    });
}),
2) }}
                    </h5>
                </div>
            </div>
        </div>
    @endforeach
</div>
Activity icon

Replied to Failed To Parse

I think you have to strip out this part: (Philippine Standard Time) because of the "Double timezone specification" (GMT+0800 already takes care of that):

Carbon::parse('Wed Mar 04 2020 13:56:00 GMT+0800');
Activity icon

Replied to How To Get Eloquent Query Between 2 Dates Including Time

You can write it with a whereRaw and between:

$now = Carbon::now('Asia/Kolkata')->toDateTimeString();

$query = Posts::where('status', '=', 'live')
    ->whereRaw("'{$now}' between `start` and `expiry`")
    ->get();
Activity icon

Replied to Use Two Foreign Keys & Two Local Keys With HasMany Relation

In your question you said your table looked like this:

Tests |id|name|description|course_id|subject_id|

Is your table name Tests or tests?

The error says that there is no column subject_id. So either your column name is wrong or the table name?

Activity icon

Awarded Best Reply on How To Use Newly Created Column In Query And Compare It Using Having?

Try this:

$selectedInfluencers = Report::query()
    ->select([
        'report_id',
        'influencer.u_id',
        DB::raw('sum(`likes` + `comments`) as `total`'),
    ])
    ->leftJoin('influencer', 'influencer.u_id', '=', 'report.u_id')
    ->whereNotNull('influencer.u_id')
    ->groupBy(['influencer.u_id', 'report_id'])
    ->havingRaw('`total` between 0 and 20000')
    ->orderBy('report_id', 'asc')
    ->paginate(15);
Mar
20
1 week ago
Activity icon

Awarded Best Reply on Laravel Nova One-to-many Polymorphic Relationship SingleLabel/uriKey Exception

Check if the types you are using are Nova resources and not models.

Activity icon

Replied to How To Use Newly Created Column In Query And Compare It Using Having?

Try this:

$selectedInfluencers = Report::query()
    ->select([
        'report_id',
        'influencer.u_id',
        DB::raw('sum(`likes` + `comments`) as `total`'),
    ])
    ->leftJoin('influencer', 'influencer.u_id', '=', 'report.u_id')
    ->whereNotNull('influencer.u_id')
    ->groupBy(['influencer.u_id', 'report_id'])
    ->havingRaw('sum(`likes` + `comments`) between 0 and 20000')
    ->orderBy('report_id', 'asc')
    ->paginate(15);
Activity icon

Replied to How To Write Sql Query In Laravel

The only way to verify this is if we can look into the actual data in the database.

Activity icon

Replied to How To Use Newly Created Column In Query And Compare It Using Having?

Try this:

$selectedInfluencers = Report::query()
    ->select([
        'report_id',
        'influencer.u_id',
        DB::raw('sum(`likes` + `comments`) as `total`'),
    ])
    ->leftJoin('influencer', 'influencer.u_id', '=', 'report.u_id')
    ->whereNotNull('influencer.u_id')
    ->groupBy(['influencer.u_id', 'report_id'])
    ->havingRaw('`total` between 0 and 20000')
    ->orderBy('report_id', 'asc')
    ->paginate(15);
Activity icon

Replied to How To Write Sql Query In Laravel

Problem is with the named parameters, even when they are named the count should still be the same...

DB::select('
SELECT
    `products`.`id`,
    `products`.`name`,
    (
        SELECT SUM(IFNULL(`stocks`.`qty`, 0))
        FROM `stocks`
        WHERE `stocks`.`pid` = `products`.`id`
        AND (
            DATE(`stocks`.`created_at`) = ?
            OR DATE(`stocks`.`created_at`) = ?
        )
    ) AS `total_stock`,
    (
        SELECT SUM(IFNULL(`loadings`.`qty`, 0))
        FROM `loadings`
        WHERE `loadings`.`pid` = `products`.`id`
        AND DATE(`loadings`.`created_at`) = ?
    ) AS `total_loadings`,
    (
        (
            SELECT SUM(IFNULL(`stocks`.`qty`, 0))
            FROM `stocks`
            WHERE `stocks`.`pid` = `products`.`id`
            AND DATE(`stocks`.`created_at`) = ?
        )
        + (
            SELECT SUM(IFNULL(`loadings`.`qty`, 0))
            FROM `loadings`
            WHERE `loadings`.`pid` = `products`.`id`
            AND DATE(`loadings`.`created_at`) = ?
        )
    ) AS `close_balance`,
    (
        (
            SELECT SUM(IFNULL(`stocks`.`qty`, 0))
            FROM `stocks`
            WHERE `stocks`.`pid` = `products`.`id`
            AND DATE(`stocks`.`created_at`) = ?
        )
        - (
            SELECT SUM(IFNULL(`loadings`.`qty`, 0))
            FROM `loadings`
            WHERE `loadings`.`pid` = `products`.`id`
            AND DATE(`loadings`.`created_at`) = ?
        )
    ) AS `open_balance`
FROM `products`
', [Carbon::today(), Carbon::yesterday(), Carbon::today(), Carbon::yesterday(), Carbon::today(), Carbon::yesterday(), Carbon::yesterday()]);
Activity icon

Replied to Laravel Nova One-to-many Polymorphic Relationship SingleLabel/uriKey Exception

Check if the types you are using are Nova resources and not models.

Activity icon

Replied to How To Write Sql Query In Laravel

There is also data on the right date? Maybe the CURDATE() - 1 is not correct, try:

DB::select('
SELECT
    `products`.`id`,
    `products`.`name`,
    (
        SELECT SUM(IFNULL(`stocks`.`qty`, 0))
        FROM `stocks`
        WHERE `stocks`.`pid` = `products`.`id`
        AND (
            DATE(`stocks`.`created_at`) = :today
            OR DATE(`stocks`.`created_at`) = :yesterday
        )
    ) AS `total_stock`,
    (
        SELECT SUM(IFNULL(`loadings`.`qty`, 0))
        FROM `loadings`
        WHERE `loadings`.`pid` = `products`.`id`
        AND DATE(`loadings`.`created_at`) = :today
    ) AS `total_loadings`,
    (
        (
            SELECT SUM(IFNULL(`stocks`.`qty`, 0))
            FROM `stocks`
            WHERE `stocks`.`pid` = `products`.`id`
            AND DATE(`stocks`.`created_at`) = :yesterday
        )
        + (
            SELECT SUM(IFNULL(`loadings`.`qty`, 0))
            FROM `loadings`
            WHERE `loadings`.`pid` = `products`.`id`
            AND DATE(`loadings`.`created_at`) = :today
        )
    ) AS `close_balance`,
    (
        (
            SELECT SUM(IFNULL(`stocks`.`qty`, 0))
            FROM `stocks`
            WHERE `stocks`.`pid` = `products`.`id`
            AND DATE(`stocks`.`created_at`) = :yesterday
        )
        - (
            SELECT SUM(IFNULL(`loadings`.`qty`, 0))
            FROM `loadings`
            WHERE `loadings`.`pid` = `products`.`id`
            AND DATE(`loadings`.`created_at`) = :yesterday
        )
    ) AS `open_balance`
FROM `products`
', ['today' => Carbon::today(), 'yesterday' => Carbon::yesterday()]);
Activity icon

Replied to Filtering Empty Arrays

Another approach:

$array = collect($array)->filter(static function ($subArray) {
    return collect($subArray)->filter()->isNotEmpty();
});
Activity icon

Replied to How To Write Sql Query In Laravel

With a query that complicated I would just execute the raw query or might consider a database view.

DB::select('
SELECT
    `products`.`id`,
    `products`.`name`,
    (
        SELECT SUM(IFNULL(`stocks`.`qty`, 0))
        FROM `stocks`
        WHERE `stocks`.`pid` = `products`.`id`
        AND (
            DATE(`stocks`.`created_at`) = CURDATE()
            OR DATE(`stocks`.`created_at`) = CURDATE() - 1
        )
    ) AS `total_stock`,
    (
        SELECT SUM(IFNULL(`loadings`.`qty`, 0))
        FROM `loadings`
        WHERE `loadings`.`pid` = `products`.`id`
        AND DATE(`loadings`.`created_at`) = CURDATE()
    ) AS `total_loadings`,
    (
        (
            SELECT SUM(IFNULL(`stocks`.`qty`, 0))
            FROM `stocks`
            WHERE `stocks`.`pid` = `products`.`id`
            AND DATE(`stocks`.`created_at`) = CURDATE() - 1
        )
        + (
            SELECT SUM(IFNULL(`loadings`.`qty`, 0))
            FROM `loadings`
            WHERE `loadings`.`pid` = `products`.`id`
            AND DATE(`loadings`.`created_at`) = CURDATE()
        )
    ) AS `close_balance`,
    (
        (
            SELECT SUM(IFNULL(`stocks`.`qty`, 0))
            FROM `stocks`
            WHERE `stocks`.`pid` = `products`.`id`
            AND DATE(`stocks`.`created_at`) = CURDATE() - 1
        )
        - (
            SELECT SUM(IFNULL(`loadings`.`qty`, 0))
            FROM `loadings`
            WHERE `loadings`.`pid` = `products`.`id`
            AND DATE(`loadings`.`created_at`) = CURDATE() - 1
        )
    ) AS `open_balance`
FROM `products`
');
Activity icon

Replied to How To Write Sql Query In Laravel

I was missing a ) in the first selectRaw, I've updated my reply, try it again.

Activity icon

Replied to How To Write Sql Query In Laravel

It might looks something like this:

DB::table('products')
    ->select(['products.id', 'products.name'])
    ->addSelect([
        'total_stock' => DB::table('stocks')
            ->selectRaw('sum(ifnull(`stocks`.`qty`, 0))')
            ->whereColumn('stocks.pid', '=', 'products.id')
            ->whereDate('stocks.created_at', '=', Carbon::today()),
        'total_loadings' => DB::table('loadings')
            ->selectRaw('sum(ifnull(`loadings`.`qty`, 0))')
            ->where('loadings.pid', '=', 'products.id')
            ->whereDate('loadings.created_at', '=', Carbon::today())
    ])
    ->get();
Activity icon

Replied to Use Two Foreign Keys & Two Local Keys With HasMany Relation

Maybe something like this:

class Test extends Model
{
    public function questions()
    {
        $this->hasMany(Question::class, 'course_id', 'course_id')
            ->whereColumn('questions.subject_id', '=', 'tests.subject_id');
    }
}
Mar
18
2 weeks ago
Activity icon

Awarded Best Reply on OrWhere Doesn't Seem To Be Working

$properties = Propery::where('propname', 'like', "%{$propname}%")
    ->where(static function ($query) use ($proptype_id, $minbeds, $category_id, $town) {
        $query->where('proptype_id', '=', $proptype_id)
            ->orWhere('bedroom', '=', $minbeds)
            ->orWhere('category_id', '=', $category_id)
            ->orWhere('town', '=', $town);
    });
Activity icon

Awarded Best Reply on I Want To Subtract Dr Field From Cr Field In My Query

Try this:

DB::raw('SELECT (SUM(`dr`) - SUM(`cr`)) AS `Total`')
Activity icon

Replied to OrWhere Doesn't Seem To Be Working

$properties = Propery::where('propname', 'like', "%{$propname}%")
    ->where(static function ($query) use ($proptype_id, $minbeds, $category_id, $town) {
        $query->where('proptype_id', '=', $proptype_id)
            ->orWhere('bedroom', '=', $minbeds)
            ->orWhere('category_id', '=', $category_id)
            ->orWhere('town', '=', $town);
    });
Activity icon

Replied to OrWhere Doesn't Seem To Be Working

Hmm that is exactly what you are doing right now, are you sure this is the query you are expecting?

Not something like:

SELECT *
FROM `Properties`
WHERE `propname` LIKE '%propname%'
AND (
    `proptype_id` = 'proptype_id'
    OR `bedroom` = 'bedroom'
    OR `category_id` = 'category_id'
)
Activity icon

Replied to OrWhere Doesn't Seem To Be Working

Hi boyjarv,

Can you send the raw sql query you want?

I can show you the active record equivalent.

Activity icon

Replied to Laravel Nova Creating User SendEmailVerificationNotification +

Hi vesst,

Why not hook into the user created event?

Activity icon

Replied to I Want To Subtract Dr Field From Cr Field In My Query

Try this:

DB::raw('SELECT (SUM(`dr`) - SUM(`cr`)) AS `Total`')