😂Form old value full (ok)
PreviousNhững mẹo hay và ngắn chúng ta thường không nhớ sử dụng.NextSử dụng .env, @import '~bootstrap, Route::has('login'), Route::has('register'), now()->subYears (ok)
Last updated
C:\xampp8\htdocs\hanam\resources\views\welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body class="antialiased">
<form action="{{ route('index') }}">
<input type="text" name="name" value="{{ old('name') }}"> <br/>
<p><label for="name">0</label><input type="radio" name="status" @if(old('status') == 0) checked @endif value="0"><label for="name">1</label><input type="radio" name="status" @if(old('status') == 1) checked @endif value="1"></p>
<p><input type="type" name="birthday" value="{{ old('birthday') }}"> use: whereDate</p>
<input type="submit" value="Submit">
</form>
@foreach ($users as $key => $user)
<p>{{ $key + 1 }}👍 Name: {{ $user->name }} Status: {{ $user->status }} Date: {{ $user->created_at }}</p>
@endforeach
</body>
</html>
C:\xampp8\htdocs\hanam\app\Http\Controllers\UserController.php
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$request->flash();
$user = User::query();
if ($request->has('name')) {
$user->where('name', 'LIKE', '%' . $request->name . '%');
}
if ($request->has('status')) {
$user->where('status', $request->status);
}
if ($request->has('birthday')) {
$user->whereDate('created_at', $request->birthday);
}
$users = $user->get();
return view("welcome")->with(compact('users'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Models\User $user
* @return \Illuminate\Http\Response
*/
public function show(User $user)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\User $user
* @return \Illuminate\Http\Response
*/
public function edit(User $user)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\User $user
* @return \Illuminate\Http\Response
*/
public function update(Request $request, User $user)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\User $user
* @return \Illuminate\Http\Response
*/
public function destroy(User $user)
{
//
}
}
C:\xampp8\htdocs\hanam\resources\views\welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body class="antialiased">
<form action="{{ route('index') }}">
<input type="text" name="name" value="{{ request()->input('name') }}"> <br/>
<p><label for="name">0</label><input type="radio" name="status" @if(request()->input('status') == 0) checked @endif value="0"><label for="name">1</label><input type="radio" name="status" @if(old('status') == 1) checked @endif value="1"></p>
<p><input type="type" name="birthday" value="{{ request()->input('birthday') }}"> use: whereDate</p>
<input type="submit" value="Submit">
</form>
@foreach ($users as $key => $user)
<p>{{ $key + 1 }}👍 Name: {{ $user->name }} Status: {{ $user->status }} Date: {{ $user->created_at }}</p>
@endforeach
</body>
</html>