Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

trevorpan's avatar

man, I'm still tinkering with this thing and have made some progress, but could still use a hand:

class JobsController extends Controller
{
    protected $job;

    public function __construct()
    {

        $this->middleware('auth')->except(['index', 'show']);

    }
....

    public function show(Job $job)
    {

        // $thumbnail = $job->getFirstMedia('document');
        $fullpageimage = $job->getFirstMedia('document');
        // $fullpageimage = Arr::first($fullpageimage);

        $downloads = $job->getMedia('document');
        // $downloads = $job->getMedia('document');
        
        $hasbidinterest = BidInterest::BidderInterested()->where('job_id', '=', $job->id)->get();
        // dd($hasbidinterest);
    

        return view('jobs.show', compact('job', 'downloads', 'fullpageimage', 'thumbnail', 'hasbidinterest')); 
    }

The JobsController has an authentication except on 'show', in this case, and it interferes with displaying the checkbox. How do you test for authenticated user for just $hasbidinterest but not interfere with the overall 'show' method?

The show method is used to display a job for anyone, not just auth()->users

here's new logic in the blade file


        @if ($hasbidinterest = true)

            Thank you for your interest in bidding this job.
            
        @else 
        
            <form action="/jobs/{{ $job->id }}/bidinterest" method="POST">
                @csrf
                <input type="checkbox" name="bidderinterested" value="1" required>

                I will bid this job.<br>
                <input type="submit" value="Submit">
            </form> 

        @endif 

When dd($hasbidinterests); the array does show all the bidders, and counts them properly. However, because the blade logic does not yield the result desired a single user can hit the button as many times as they like and the array will count the user 3 times if they clicked the checkbox 3 times, etc.

Thank you anyone ~

Cronix's avatar

It sounds like someone who isn't logged in then shouldn't see that form? Why not hide it from them if they aren't logged in?

You have multiple issues here besides that.

@if ($hasbidinterest = true)

You are assigning true to $hasbidinterest, not seeing if $hasbidinterest is true.

Besides that, why would it be true? It's an eloquent collection.

$hasbidinterest = BidInterest::BidderInterested()->where('job_id', '=', $job->id)->get();

what does BidderInterested() do?

trevorpan's avatar

@CRONIX - Here's BidInterest.php

public static function scopeBidderInterested($query)
    {
        return $query->where('bidderinterested', 1);
    }

trying to reference the scope query, and ensure the authenticated user is prohibited from seeing the checkbox if they clicked it.

Other users should see the box so they are enticed to whip out their wallets, and place a bid..

hha

that's right, I forgot on the one =, == is what tests for a condition?

trevorpan's avatar
trevorpan
OP
Best Answer
Level 15

@SNAPEY -

$hasbidinterest = auth()->user()->bidInterests()->where('job_id',$job->id)->bidderInterested()->exists();

man, finally got this thing. Your method uses Auth::user which returns:

Class 'App\Http\Controllers\Auth' not found

Why does the basic logic work with auth()->user(), etc and not Auth::user?

Basic things to fix. (for future users)

  1. Routes needed to be cleaned up. (see above)

  2. bidinterest had to be on JobsController@show, not BidInterestsController@show.

  3. By declaring auth()->user()-> I was able to leave the Jobs page without authentication (see a few posts up) under the @show method - so guests can see jobs - but tested the user, if authenticated, so they don't falsely increase the competition.

success!

Thank you @snapey and thank you @cronix

Snapey's avatar

auth() is a helper for the Auth class

This

Class 'App\Http\Controllers\Auth' not found

is caused by not importing Auth into your class

namespace App\Http\Controllers;

use Auth;

class MyController extends Controller
{

trevorpan's avatar

@SNAPEY - ok, cool I'll keep that in mind. Still trying to grasp all the globally available things vs imported/namespaced.

Man that was an epic journey on this post!

Really appreciate your help`

Previous

Please or to participate in this conversation.