Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Laravel - Controller get select value from Views

//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 AppHttpControllers;

use AppArticle;
use AppCatalog;
use AppUser;
use AppHttpControllersController;
use App;
use IlluminateHttpRequest;

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);
    }
}
Comment

Laravel - Controller get select value from Views

public function index(Request $request)
    {
        $locale = Request::segment(1);
        $view = 'home';
        $article_year = $request->get('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', $article_year)->orderBy('sort_num', 'desc')->get();
        $data['news'] = (new Article())->where('is_active', 0)->where('user_year', $article_year)->orderBy('sort_num', 'desc')->get();       

        return view($view, $data);
    }

//and

use IlluminateHttpRequest;
Comment

PREVIOUS NEXT
Code Example
Php :: get original data without cast laravel 
Php :: carbon get difference between two dates in years and months 
Php :: php define associative array 
Php :: caculator 
Php :: laravel faker car plate br 
Php :: array inserted in laravel 
Php :: laravel sintax 
Php :: illuminate routing array to string conversion 
Php :: infoplist codepush key 
Php :: function to fetch user details 
Php :: ci4+ connection code 
Php :: php convert timestamp to datetime 
Php :: Add Payment Type to WooCommerce Admin Email 
Php :: plesk change php version 
Php :: null check nested object laravel 
Php :: unexpected variable 
Php :: laravel | eloquent | db | randomly fetch | query data 
Php :: laravel gigapay list invoice 
Php :: Get page title, excerpt or content by id 
Php :: laravel count 
Php :: index.php when deploying 
Php :: how to access session value passed to sub domain 
Php :: default time zone for europe php 
Php :: add multi product at the same time using repearter default view laravel 
Php :: laravel soft delete 
Php :: php opencart controller 
Php :: php code for adding dara 
Php :: numeros positivos input laravel 
Php :: Round Number Up 
Php :: php text in thml 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =