Hello guys,
I am new here and new Laravels programmer generally.
I need you advice about how to get select option and filter results based on this.
Blade:
<select name="sortJobs" id="sortJobs">
<option value="Software development">Software development</option>
<option value="Design & UX">Design & UX</option>
<option value="Marketing">Marketing</option>
<option value="Customer support">Customer support</option>
<option value="Other">Other</option>
</select>
@foreach ($jobs as $job)
<p>{{ $job->company }}</p>
...etc
@endforeach
Controller:
<?php
namespace App\Http\Controllers\Website;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Job;
use DB;
class WelcomeController extends Controller
{
/* Show the welcome page
@return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$category = $request->get('sortJobs');
$query = DB::table('jobs')->where('visible', 1);
if ($category !== null ) {
$query->where('category', $category);
}
$jobs = $query->paginate(15);
return view("website.welcome", compact('jobs'));
}
}
I have no JavaScript for this, do I need one?
dd($request->all()); returns NULL.
'Job' is table and 'Category' is column for every 'Job' in database.
What is wrong with this code? How to make it work?
Thanks in advance!