หลังจากกด Save Laravel ไม่บันทึกลง Database ไม่ redirect ไปหน้า user รบกวนช่วยดูด้วยค่ะ
หน้าแรก Code (PHP)
http://localhost:8000/user
Home page
Add
//Route Code (PHP)
Route::resource('user','UserController');
//Controller Code (PHP)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class UserController extends Controller
{
/**
* แสดงผล
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view ('user.index');
}
/**
* เพิ่มข้อมูล
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view ('user.create');
}
/**
* บันทึกข้อมูล
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request,['fname_sname'=>'required','user_email'=>'required','status'=>'required']);
$user = new User(
[
'fname_sname'=>$request->get('fname_sname'),
'user_email'=>$request->get('user_email'),
'status'=>$request->get('status')
]);
$user->save();
return redirect()->route('user.index')->with('success','Save Success');
}
}
//Model Code (PHP)
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $filable=['fname_sname','user_email','status'];
}
//Database Code (PHP)
SELECT TOP (1000) [emp_id]
,[fname_sname]
,[user_email]
,[status]
,[create_user]
,[update_user]
,[created_at]
,[updated_at]
FROM [db_laravel].[dbo].[users]