public function __invoke(){
}
Route::get('demo19', 'TestTestController');
Route::fallback(function () {
return redirect('/');
});
dump(Route::current());
echo Route::currentRouteName();
echo Route::currentRouteAction();
HTTP请求方式 | URL | 控制器方法 | 路由命名 | 业务逻辑描述 |
---|
GET | post | index() | post.index | 展示所有文章 |
GET | post/create | create() | post.create | 发布文章表单页面(api无) |
POST | post | store() | post.store | 获取表单提交数据并保存新文章 |
GET | post/{id} | show() | post.show | 展示单个文章 |
GET | post/{id}/edit | edit() | post.edit | 编辑文章表单页面(api无) |
PUT | post/{id} | update() | post.update | 获取编辑表单输入并更新文章 |
DELETE | post/{id} | destroy() | post.destroy | 删除单个文章 |
Route::resource('api', 'TestApiController');
Route::apiResource('api', 'TestApiController');
Route::resources([
'api'=>'TestApiController'
]);
$result = DB::table('uinfo')
->orderBy('id')
->chunk(100, function ($result) {
foreach ($result as $item) {
$item->username = $item->username . '###22';
}
});
DB::table('uinfo')->where('id', 19)->exists();
DB::table('uinfo')->where('id', 19)->doesntExist()
$base = DB::table('uinfo')->select('username', 'password');
$result = $base->addSelect('updated_at')->get();
$result = DB::table('uinfo')->select(DB::raw('count(*) as num'))
->groupBy('username')
->get();
$result=DB::table('uinfo')
->groupBy('username')
->selectRaw('count(*) as num,username')
->get();
$result = DB::table('uinfo')->updateOrInsert(
['id' => 15],
['username' => 'demo14的测试1', 'password' => '123456', 'updated_at' => $time, 'created_at' => $time]
);
composer require barryvdh/laravel-ide-helper
php artisan ide-helper:generate – 为Facades 生成注释
php artisan ide-helper:models – 为数据模型生成注释
php artisan ide-helper:meta – 生成PhpStorm Meta file
public function scopeCheckId($query, $index)
{
return $query->where('id', '>', $index);
}
$result = Uinfo::checkId(5)->get();
namespace AppScopes;
use IlluminateDatabaseEloquentBuilder;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentScope;
class NameScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
return $builder->where('id', '>', 6);
}
}
protected static function boot()
{
parent::boot();
static::addGlobalScope(new NameScope());
}
public function getUsernameAttribute($value)
{
return '[' . $value . ']';
}
protected $appends = ['info'];
public function getInfoAttribute()
{
return '##'.$this->password;
}
public function setPasswordAttribute($value)
{
$this->attributes['password'] = '&&' . $value;
}
public function be_user()
{
return $this->belongsTo(Uinfo::class, 'u_id', 'id');
}
$result = Ucard::with('be_user')->get();
$result = Ucard::with(['be_user' => function ($query) {
$query->where('id', '>', 5);
}])->get();
public function userCard()
{
return $this->Hasone(Ucard::class, 'u_id', 'id');
}
$result = Uinfo::find(15)->userCard()->save(new Ucard(['card' => '15646484']));
Uinfo::find(15)->userCard()->create(['card' => 2525]);
Uinfo::find(15)->userCard()->update(['card' => '修改']);
Uinfo::find(9)->userCard()->delete();
public function rel_article()
{
return $this->belongsToMany(Keyword::class, 'a_k', 'a_id', 'k_id');
}
$k_id = 6;
Article::find(1)->rel_article()->attach($k_id, ['remarks' => '多对多增加']);
Article::find(1)->rel_article()->sync($k_id);
Article::find(1)->rel_article()->detach($k_id);
Article::find(1)->rel_article()->updateExistingPivot(3, ['remarks' => '修改']);