小编Ken*_*rna的帖子

Laravel - 在 web.php 以外的文件中创建路由

在 web.php 中制作网站各个页面的路由,使其变得庞大且非结构化。所以我的问题是有没有办法将它保存在单独的文件中?

// Calling Registration function
Route::any('/admin-store','AdminUserController@store')->name('admin-reg'); 

// Redirecting to Registration page
Route::get('/admin-registration','AdminUserController@index')->name('admin-registration'); 

// Redirecting to login page
Route::get('/admin-login','AdminLoginController@index')->name('admin-login'); 

// Redirecting to Admin Profile Page
Route::get('/admin-profile','AdminProfileController@index')->name('admin-profile'); 

// Calling Login function
Route::post('admin-login-result','AdminLoginController@login')->name('admin-log'); 

// Calling Function to Update Profile
Route::post('admin-edit-profile','AdminEditController@updateProfile')
         ->name('admin-edit-profile'); 

// Redirecting to Profile Edit page
Route::get('/admin-edit-profile','AdminEditController@index')->name('admin-edit'); 
Run Code Online (Sandbox Code Playgroud)

laravel laravel-5

4
推荐指数
1
解决办法
2811
查看次数

Laravel Eloquent 在单个键值对中获取所有内容

我有两个表posts,post_metas架构如下:

POSTS
+------------+------------------+
| Field      | Type             |
+------------+------------------+
| id         | int(10) unsigned |
| title      | varchar(255)     |
| content    | longtext         |


POST_METAS
+------------+------------------+
| Field      | Type             |
+------------+------------------+
| id         | int(10) unsigned |
| post_id    | int(10) unsigned |
| key        | varchar(255)     |
| value      | longtext         |
Run Code Online (Sandbox Code Playgroud)

使用简单的一对多关系,我得到这个输出

POSTS
+------------+------------------+
| Field      | Type             |
+------------+------------------+
| id         | int(10) unsigned |
| title      | varchar(255)     |
| …
Run Code Online (Sandbox Code Playgroud)

php laravel eloquent

4
推荐指数
1
解决办法
7089
查看次数

Laravel 上的“Action App\Http\Controllers\CommentRepliesController@createReply 未定义”错误

我正在尝试添加一个选项来回复对帖子的评论,但我一直收到:

CommentRepliesController@createReply 未定义。

通过添加对帖子的回复PostCommentsController@store效果很好。但是,当我尝试通过返回帖子或直接comment/reply在 URL 中添加对评论的回复时,它给了我上面的错误。

以下是我的路线:

Route::group(['middleware'=>'auth'], function(){
    Route::resource('comment/reply', 'CommentRepliesController@createReply');
});
Run Code Online (Sandbox Code Playgroud)

以下是我的CommentRepliesController@createReply:

public function createReply(Request $request){
    $user = Auth::user();
    if($user->photo){
        $data = [
        'comment_id' => $request->comment_id,
        'author' => $user->name,
        'email' => $user->email,
        'photo' => $user->photo->file,
        'body' => $request->body
    ];       
    } else{
        $data = [
        'comment_id' => $request->comment_id,
        'author' => $user->name,
        'email' => $user->email,
        'body' => $request->body
    ];
    }

    CommentReply::create($data);
    $request->session()->flash('reply_message', 'Your reply has been submitted 
                                 and is awaiting moderation.');
    return redirect()->back();

}
Run Code Online (Sandbox Code Playgroud)

以下是我的 …

php sql lamp laravel

4
推荐指数
1
解决办法
1854
查看次数

如何重试 Laravel Horizo​​n 中 Redis 队列中的所有失败作业

如何重试Laravel Horizo​​n 中所有失败的作业?似乎没有“全部重试”按钮,并且 artisan 命令不起作用,因为失败的作业未存储在表中。

php laravel laravel-5 laravel-horizon laravel-5.8

4
推荐指数
1
解决办法
1万
查看次数

Laravel 可修订获取特定用户的所有修订列表

我正在使用VentureCraft/revisionable 包,它在自述文件中向我展示了如何显示具有修订的模型的修订:

@foreach($account->revisionHistory as $history )
    <li> 
         {{ $history->userResponsible()->first_name }} 
         changed {{ $history->fieldName() }} 
         from {{ $history->oldValue() }} 
         to {{ $history->newValue() }}
    </li>
@endforeach
Run Code Online (Sandbox Code Playgroud)

但我想要一个由特定用户完成的所有修订的列表;如何做到这一点?所以我可以显示由一个特定用户完成的修订历史。

laravel revisionable laravel-5

3
推荐指数
1
解决办法
870
查看次数

试图获取非对象错误的属性-Laravel

我正在开发中laravel一个博客,我有两个表之间有外键的麻烦:posts和categories。

我创建了两个模型:(Post用于职位表)和Category(用于类别表)。在我看来,我编写了以下代码:<p>Posted In: {{$post->category->id}}</p>,但是此错误正在显示:

ErrorException:试图获取非对象外键错误的属性

职位模型:

class Post extends Model
{
    public function category()
     {
        return $this->belongsTo('App\Category');
    }
}
Run Code Online (Sandbox Code Playgroud)

类别型号:

class Category extends Model
{
    public $table = 'categories';  

    public function posts() 
    { 
        return $this->hasMany('App\Post');
    }
}
Run Code Online (Sandbox Code Playgroud)

查看表格:

@extends('main')

@section('title', "| $post->title " )

@section('content')

    <div class="row">
        <div class ="col-md-8></col-md-8 col-md-offset-2"> 
            <h1>{{$post->title}}</h1>
            <p>{{$post->body}}</p>
            <hr>
            <p>Posted In:{{$post->category->id}}</p>
        </div>
    </div>
@endsection
Run Code Online (Sandbox Code Playgroud)

我希望代码:<p>Posted In: {{$post->category->id}}</p> 将在博客文章中输出类别。

php laravel

3
推荐指数
1
解决办法
747
查看次数

Laravel 7 HTTP 客户端 - 无法使用“body”发送 POST 请求

使用 Laravel 7.6 及其内置的 HTTP 客户端。

body我正在尝试将原始 JSON 格式的简单 POST 请求发送到我的其他域,但没有成功:

$response = Http::post('https://example.com', [
    'body' => '{ test: 1 }'
]);
Run Code Online (Sandbox Code Playgroud)

我收到 400 Bad Request - 客户端错误 - 因为我的服务器期望body这是强制性的。

我在这里缺少什么?

http request laravel guzzle laravel-7

3
推荐指数
1
解决办法
1万
查看次数

Laravel 中嵌套 api 资源时如何避免无限循环?

我有两个模型:Company和Representative。代表属于公司,公司有多名代表。

我还有两个相应的资源。

公司资源:

public function toArray($request)
    {
        return [
            'id'          => $this->id,
            'title'       => $this->title,   
            'representatives' => RepresentativeResource::collection($this->representatives)
        ];
    } 
Run Code Online (Sandbox Code Playgroud)

代表资源:

 public function toArray($request)
    {
        return [
            'id' => $this->id,
            'company' => $this->company ? new CompanyResource($this->company) : null
        ];
    }
Run Code Online (Sandbox Code Playgroud)

我想要实现的目标是,当我找到公司时,我想找到他们的代表。当我获得代表时,我想获得有关公司的信息。

发生的是无限循环:它们无限地相互包含。

那么,如何解决呢?

laravel laravel-5

2
推荐指数
1
解决办法
2614
查看次数

将参数传递给数据表的每一列

在我的 Laravel 5.6 应用程序中,我尝试将一个$id变量从我的路由传递到我的数据表的每一列。

我的代码:

 public function getVendorslistChange($id){
    try {
        return Datatables::of($this->purchaseRepository->getVendorListData(),$id)
            ->addColumn('action', function ($vendor,$id) {
                return \Form::open(['method' => 'POST', 'action' => ['PurchaseController@postChangeVendor',$id], 'class' => 'form']) . '
                <input type="hidden" name="id" value="' . $vendor->id . '" />
                <input type="submit" name="submit" value="Choose" class="btn center-block" />
                ' . \Form::close();
            })
            ->make(true);
    } catch (\Exception $e) {
        return $this->redirectWithErrors($e);
    }
}
Run Code Online (Sandbox Code Playgroud)

这部分$this->purchaseRepository->getVendorListData()将返回以下内容:

public function getVendorListData(){
    $this->vendors = Vendor::Select(
        array(
            'vendors.id',
            'vendors.company_name'
        ))
        ->where('vendors.company_id',return_company_id())
        ->where('status','Active')->get()
    ;
    return $this->vendors;
}
Run Code Online (Sandbox Code Playgroud)

但是有错误说, …

datatable laravel laravel-datatables

2
推荐指数
1
解决办法
4147
查看次数

Laravel Forge 上的 Laravel Nova 错误 403 页面

我在 Laravel Forge 上使用 Laravel Nova 部署了我的 Laravel 应用程序。我用路径存储库安装了 Nova,我也有 Nova 用户。我替换了 NovaServiceProvider Gate 方法,如:

 Gate::define(‘viewNova’, function ($user) {

     return in_array($user->email, [

         ‘my@license.com’,

     ]);

 });
Run Code Online (Sandbox Code Playgroud)

当我访问页面“/nova”时,有登录表单,但是当我尝试使用现有用户登录时,它会显示 403 错误页面并显示消息“对不起,您被禁止访问此页面”

我找到的唯一一篇文章是Medium 上的“设置 Laravel Nova 时的常见问题”。

问题#2:看起来像我的问题,但事实并非如此。我认为我的问题与许可证有关,否则,我尝试了所有方法。

我有一个单独的 Nova 许可证,我不必通过电子邮件向支持人员询问他们。

我有: Laravel5.7和 Nova:1.3.1

我的问题是:我应该购买专业版许可证吗?为什么?或者有什么问题?

php laravel laravel-forge laravel-nova

2
推荐指数
1
解决办法
3257
查看次数