don't show checkbox if auth()->user has submitted checkbox

Posted 6 months ago by trevorpan

Hi, this form shows how many interested bidders there are for a given job. After a user_id has submitted interest to bid, the blade takes away the possibility of resubmitting the form.

http://trevorpan.com/stuff/bidders.jpg http://trevorpan.com/stuff/bidders2.jpg

Having a real tough go on getting the auth()->user to be the conditional. Sometimes they'll hide a form. But then when I log in as another user it shows without form, etc. Feels like whack-a-mole.

    //class BidInterestsController extends Controller @ show


    // $userbidinterests = DB::table('bidinterests')
        //     ->where('user_id', '==', auth()->user->id)->get();
        
        $userbidinterests = DB::table('bidinterests')
                                ->whereExists(function ($query) {
                                    $query->select(DB::raw(1))
                                          ->from('bidderinterested')
                                          ->whereRaw('bidderinterested.user_id = users.id');
                                })
                                ->get();

The blade logic

        @if (!$job->userbidinterests)
            <form action="/jobs/{{ $job->id }}/bidinterests" method="POST">
                @csrf
                <input type="checkbox" name="bidderinterested" value="1" required> I will bid this job.<br>
                <input type="submit" value="Submit">
            </form> 
        @else 
            Thank you for your interest in bidding this job.
        @endif

Please sign in or create an account to participate in this conversation.