我正在研究laravel 5.1.我已经使用remember me功能创建了登录功能.
我在auth函数的帮助下检查用户身份验证:
$this->auth->attempt(['email' => $email, 'password' => $request->input('password')], true)
Run Code Online (Sandbox Code Playgroud)
从登录时选中复选框并提交登录详细信息,它将创建一个这样的cookie令牌:
remember_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Run Code Online (Sandbox Code Playgroud)
但是当我通过此功能注销时,
$this->auth->logout()
登录不显示填充的先前登录详细信息,并且此cookie令牌也被销毁.
例如,模型有很多属性,但在 select 中我只指定了几个属性。
$listings = Realty::select('city', 'mls', 'class_id')->get();
Run Code Online (Sandbox Code Playgroud)
如何使一个特质(prefebable)或类继承 Eloquent,如果我尝试访问不在 select 中的属性,它将抛出异常:
$propertyType = $listings[0]->property_type; // returns `null`, but I need
// RuntimeException or ErrorException
Run Code Online (Sandbox Code Playgroud) 我有一个混合使用Laravel和Angular路由的问题,同时尝试捕获我的非Laravel路由并呈现Angular视图.
我在app\http\route.php中添加了丢失的方法后出现以下错误:
Facade.php第216行中的FatalErrorException:调用未定义的方法Illuminate\Foundation\Application :: missing()
我知道这对laravel 5或者down版本可以正常工作,但是我目前没有使用laravel 5.2,那么如何在laravel 5.2中编码?有解决方案吗
route.php看起来像:
<?php // app/routes.php
// HOME PAGE ===================================
// I am not using Laravel Blade
// I will return a PHP file that will hold all of our Angular content
Route::get('/', function() {
View::make('index'); // will return app/views/index.php
});
// API ROUTES ==================================
Route::group(['prefix' => 'api'], function() {
// Angular will handle both of those forms
// this ensures that a user can't access api/create or api/edit when there's nothing there …Run Code Online (Sandbox Code Playgroud) TLDR:当SoftDeletes特征包含在我的父模型中时,我不再将父模型的软删除实例作为子动态属性.如何才能做到这一点?
我已经定义了几个基本模型,如下所示:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Builder;
class User extends Model
{
use SoftDeletes;
public function posts()
{
return $this->hasMany("App\Post");
}
}
class Post extends Model
{
public function user()
{
return $this->belongsTo("App\User");
}
public function scopePending(Builder $query)
{
return $query->whereNull("pending");
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我想列出待处理的帖子,所以我这样做:
<?php
namespace App\Controllers;
use App\Post;
class PostController extends Controller
{
public function index()
{
$posts = Post::pending()->get();
return view("post.index", ["pending"=>$posts]);
}
}
Run Code Online (Sandbox Code Playgroud)
最后,在我看来:
@foreach($pending as $post)
{{ $post->title }}<br/>
{{ …Run Code Online (Sandbox Code Playgroud) 您好我需要解密cookie的值.我创建和销毁的代码:
public function setSession($id){
Cookie::queue('userId', $id, 10000);
}
public function destroySession(){
Cookie::queue(Cookie::forget('userId'));
}
Run Code Online (Sandbox Code Playgroud)
但我需要在没有加密的情况下获得cookie的价值.
我不知道我在做什么错,因为它可以与应用程序中的所有其他模型一起使用。我刷新并重新播种了数据库多次。并且这些模型扩展了相同的抽象方法
这是控制器中的代码:
$substrates = $this->substrates->all()->toArray();
$temp = json_encode($substrates);
dd($temp, json_last_error(), json_last_error_msg(), $substrates);
Run Code Online (Sandbox Code Playgroud)
这是dd()的输出:false 8“不支持类型”
数组:119 [?
0 => array:21 [?
"id" => 1
"name" => "Wood Free"
"machine_id" => 2
"classification" => "Cover"
"origins" => "Coming Soon"
"duplex" => true
"color" => "Translucents"
"texture" => "Leather"
"finish" => "Felt"
"product_type" => "Sheet"
"caliper" => "0.06"
"m_weight" => 70
"width" => "46.40"
"height" => "32.00"
"pic" => stream resource @17 ?}
"price" => "0.30"
"created_by" => 38
"updated_by" => 16
"deleted_at" …Run Code Online (Sandbox Code Playgroud) 我正在困扰Laravel的一个问题.我有一个名为新闻的模型
class News extends Model {
protected $fillable = ['title', 'content', 'published_at'];
protected $dates = ['created_at', 'updated_at', 'published_at'];
public function author() {
return $this->belongsTo(User::class, 'user_id');
}
public function setPublishedAtAttribute($value) {
return Carbon::createFromFormat('d/m/Y H:i', $value)->toDateTimeString();
}
public function scopePublished($query) {
return $query->whereDate('published_at', '<', Carbon::now());
}
public function scopeLatestNews($query) {
return $query->latest()->with('author');
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试存储新的新闻资源时:
public function store(StoreBlogPost $request) {
$news = Auth::user()->news()->create($request->all());
return redirect()->route('blog.show', $news);
}
Run Code Online (Sandbox Code Playgroud)
我收到了一个QueryException SQLSTATE [HY000]:一般错误:1364字段'published_at'没有默认值.
查询看起来像那样
insert into `news` (`title`, `content`, `user_id`, `updated_at`, `created_at`)
但是当我删除mutator setPublishedAtAttribute时,错误消失但我得到了一个非格式化的日期错误(这就是我使用mutator的原因).
我有Ability和Hero模型。这种关系是多对多的。
当我返回集合时,我可以使用 Hero::with('Abilities')->get()
有没有办法用单个模型(例如$hero->with('Abilities')->get())来实现这一点?
设想:
数据库中的 和 分别是和,startdate并且正常工作的查询是,enddata2015-07-202015-07-30
Model::whereBetween('startdate',array('2015-07-30','2015-08-10'))->get();
Run Code Online (Sandbox Code Playgroud)
查询从表中返回 1 条记录,这是预期结果。现在我期望的是一个小小的改变。2015-07-30考虑到日期不在中间,查询不应检索记录2015-07-30。我该如何实现这一目标?
如何在laravel 5.1中实现rememeber me功能?谁能举个例子?
laravel ×10
laravel-5 ×10
php ×10
eloquent ×6
laravel-5.1 ×2
angularjs ×1
json ×1
laravel-5.2 ×1
soft-delete ×1