Yamato

Yamato

Member Since 4 Months Ago

Experience Points
50
Total
Experience

4,950 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
0
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.

Level 1
50 XP
Apr
29
4 months ago
Activity icon

Started a new Conversation How Can I Do A Laravel Filter That Accepts Two Inputs Or Just One

So, i have a database with students, and i have, names, group name of students, and something like that, I want to make a filter system, with multiple filter, for example i want to display row (of table) with Students with name John and are in group A (both conditions must be). But the problem is when i want a filter only for students, for example i don't need a particular group, my script doesn't work, only for two filters, no only one.

I tried this:

in route: Route::post('/search', '[email protected]')->name('search'); in HomeController:

public function search(Request $request)
{
     $students = Student::query();
     $datas = $request->all();
    

    if ($request->has('group')) {
        $students = $students->where('group', $request->group);
    }

    if ($request->has('name')) {
        $students = $students->where('name', $request->name);
    }
    
    $students = $students->paginate(40);
    $data = array (
        'students' => $students,
        'datas' => $datas,
    );
    return view('searchStudent')->with($data);
}

And in blade, two simple inputs, button, and the table with students.

<div class="col-sm-4">
   <div class="search-box grey lighten-3">
      <h2>Search Students</h2>
      <div class="input-r">
         <form action="{{ route('search') }}" method="post">
            @csrf
            <input name="name" type="text" class="form-control">
            <input name="group" type="text" class="form-control">
            <button class="btn btn-info btn-block" type="submit">Search</button>
         </form>
      </div>
   </div>
</div>
<div class="col-sm-8">
   @foreach ($students as $student)
   <div class="row pb-5">
      <div class="col-md-4">
         <div class="profiel-img">
            <img src="{{ asset($student->image) }}" alt="thumbnail" class="img-thumbnail" style="width: 200px">
         </div>
         <a class="btn btn-primary btn-sm" style="font-size: 12px; margin-left: 40px;" href="{{ route('student.show', $student) }}">Visit Profile</a>
      </div>
      <div class="col-md-8 pb-3">
         <h3 class="black-text"> {{ $student->name }}</h3>
         <h3 class="black-text"> {{ $student->group }}</h3>
         <hr style="border-top:1px solid #ccc;">
      </div>
   </div>
   @endforeach
   {{ $students->appends($datas)->links() }}
</div>

I need to work for only name input, and filter, only for group, and for both input. With this code, it works only for both (i can't filter only name, only group, etc. )