라라벨 7.x 소스를 8.x 에서 사용하면 고쳐야 할 내용 (1)
Form Example in Laravel 8 - DEV Community
Form Example in Laravel 8
Laravel 8 form example tutorial. In this post, i will teach from starting on how to send form data on...
dev.to
Blade 템플릿 문법이 달라졌다.
그리고
model 도 참조할 경우
use App\Models\Post;
처럼 Post모델을 포함시켜줘야 찾는다.
PostController.php 파일을 수정한다.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Post;
class PostController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('add-blog-post-form');
}
/**
* 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)
{
$post = new Post;
$post->title = $request->title;
$post->description = $request->description;
$post->save();
return redirect('add-blog-post-form')->with('status', 'Blog Post Form Data Has Been inserted');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
WARNING You're browsing the documentation for an old version of Laravel. Consider upgrading your project to Laravel 9.x.
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
laravel.com
{!! Form::open(['route' => ['todos.destroy', $todo->id], 'method' => 'POST']) !!}
Forms & HTML - Laravel - The PHP Framework For Web Artisans
Controllers - Laravel - The PHP Framework For Web Artisans
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
laravel.com
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
laravel.com
<!DOCTYPE html>
<html>
<head>
<title>Laravel 8 Form Example Tutorial</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
@if(session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
<div class="card">
<div class="card-header text-center font-weight-bold">
Laravel 8 - Add Blog Post Form Example
</div>
<div class="card-body">
<form name="add-blog-post-form" id="add-blog-post-form" method="post" action="{{url('store-form')}}">
@csrf
<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<input type="text" id="title" name="title" class="form-control" required="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Description</label>
<textarea name="description" class="form-control" required=""></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</body>
</html>