<script srt="{{asset('/js/***.js')}}"></script> -> public/js/***.js
タイプ一覧
$table->increments('id'); //ID 自動採番(主キー)
$table->string('email'); // VARCHARカラム
$table->string('name', 100); // VARCHAR長さ指定カラム
$table->integer('price'); // INTEGERカラム
$table->text('description'); // TEXTカラム
$table->dateTime('created_at'); // DATETIMEカラム
$table->boolean('confirmed'); // created_atとupdate_atのカラムの追加
$table->json('meta'); // JSONカラム
$table->timestamps();
オプション
// NULLの許可
$table->string('email')->nullable();
// 一意の値に限定する
$table->string('email')->unique();
Laravelの変数の参照
{{ $val_of_laravel }}
Vue.jsなどを利用する場合
@{{ val_of_vue }}
コントローラ
public function somefunc(Request $request)
{
// Validation
$validator = Validator::make($request->all(),[
'item_name' => 'required|max:5',
]);
// Error時の処理
if ($validator->fails()){
return redirect('/')
->withInput()
->withErrors($validator);
}
}
ビュー
{{--Book登録フォーム--}}
<form action="{{ url('/books') }}" method="POST" class="form-horizontal">
{{ csrf_field() }}
{{--Bookのタイトル--}}
<div class="form-group">
<label for="book" class="col-sm-3 control-label">
Book
</label>
<div class="col-sm-6">
<input type="text"
name="item_name"
id="book-name"
class="form-control"
value="{{ old('item_name') }}"> # これ。nameの値と一致させる。
</div>
</div>
{{--Book登録ボタン--}}
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-default">
<i class="glyphicon glyphicon-plus"></i> Save
</button>
</div>
</div>
</form>
@if (Auth::check())
ログインしています。
@else
ログインしていません。
@endif
php artisan make:auth
php artisan migrate # laradockのworkspaceで
コントローラー単位で認証後にページを表示するように設定するには、コントローラーに以下のように記載する。
public function __construct()
{
$this->middleware('auth');
}
ユーザ登録後にリダイレクトするページを設定。
#変更前
Route::get('/home', 'HomeController@index')->name('home');
# 変更後
Route::get('/home', 'BooksController@index')->name('home');
bladeファイルを日本語に切り替える
- login.blade.php
- register.blade.php
Auth::user->name
auth()->user->name
tinker開始
php artisan tinker
$all = App\Book::all();
$item_number1 = App\Book::where('item_number', 1)->get();
$item_amount1000 = App\Book::where('item_amount', 1000)->get();
$get = App\Book::where('item_number', 1)
->orderBy('id', 'desc')
->take(10)
->get();
$get = App\Book::find(1);
$get = App\Boo::where('id', 1)->first();
Kindle Unlimitedで読める。