Laravel - Contrôleur Obtenez la valeur de sélection à partir des vues
//route-web.php
Route::get('/', 'HomeController@index')->name('home');
Route::post('/', 'HomeController@index');
//blade.php
<form>
<select name="article_year">
@foreach ($year as $item)
<option value="{{ $item->name}}">{{ $item->name}}</option>
@endforeach
</select>
<input type="submit" value="Submit Form" />
</form>
///Controller
<?php
namespace App\Http\Controllers;
use App\Article;
use App\Catalog;
use App\User;
use App\Http\Controllers\Controller;
use App;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function index(Request $request)
{
$view = 'home';
$value = $request->article_year;
$data['year'] = (new Catalog())->where('catalog_type_id', 3)->where('is_active', 1)->orderBy('sort_num', 'asc')->get();
$data['news_pin'] = (new Article())->where('is_active', 1)->where('user_year', $value)->orderBy('sort_num', 'desc')->get();
$data['news'] = (new Article())->where('is_active', 0)->where('user_year', $value)->orderBy('sort_num', 'desc')->get();
return view($view, $data);
}
}
SAMER SAEID