Php 回到一个我没有参加过的Laravel项目';t在几个月内接触过,并收到了一份;compact():未定义变量:operator";错误
每当我试图访问某个视图时,都会收到此错误。遗憾的是,这个错误并没有说明为什么会发生这种情况。这个项目在一个月前运作良好,我想从那以后我没有做任何改变,但当我今天检查出来时,我发现了错误 你知道为什么会这样吗Php 回到一个我没有参加过的Laravel项目';t在几个月内接触过,并收到了一份;compact():未定义变量:operator";错误,php,laravel,Php,Laravel,每当我试图访问某个视图时,都会收到此错误。遗憾的是,这个错误并没有说明为什么会发生这种情况。这个项目在一个月前运作良好,我想从那以后我没有做任何改变,但当我今天检查出来时,我发现了错误 你知道为什么会这样吗 C:\MAMP\htdocs\Art\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php * @return \Illuminate\Database\Query\Builder|static
C:\MAMP\htdocs\Art\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php
* @return \Illuminate\Database\Query\Builder|static
*/
public function orWhereNotExists(Closure $callback)
{
return $this->orWhereExists($callback, true);
}
/**
* Add an exists clause to the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $boolean
* @param bool $not
* @return $this
*/
public function addWhereExistsQuery(self $query, $boolean = 'and', $not = false)
{
$type = $not ? 'NotExists' : 'Exists';
$this->wheres[] = compact('type', 'operator', 'query', 'boolean');
$this->addBinding($query->getBindings(), 'where');
return $this;
}
/**
* Handles dynamic "where" clauses to the query.
*
* @param string $method
* @param string $parameters
* @return $this
*/
public function dynamicWhere($method, $parameters)
{
$finder = substr($method, 5);
$segments = preg_split(
'/(And|Or)(?=[A-Z])/', $finder, -1, PREG_SPLIT_DELIM_CAPTURE
);
Arguments
"compact(): Undefined variable: operator"
发生这种情况的视图:
@extends('layouts.app')
@section('content')
<div class="artwork-flexbox">
<div class="artwork-container">
<a href='{{url("storage/uploads/images/specificImages/".$image->image_file_name)}}'>
<img class='specific-image' src='{{url("storage/uploads/images/specificImages/".$image->image_file_name)}}' alt='Random image' />
</a>
@foreach($subImages as $subImage)
<a href='{{url("storage/uploads/images/specificImages/".$image->image_file_name)}}'>
<img class='specific-image' src='{{url("storage/uploads/images/specificImages/".$subImage->image_file_name)}}' alt='Random image' />
</a>
@endforeach
</div>
<div class="artwork-info-container">
<p class='author'>
<a href='{{ route('profile', $author->username)}}'>
<img class='profile-picture' src='{{url("storage/uploads/profile_pictures/edited/".$author->image_file_name)}}'>
{{$author->username}}
</a>
</p>
<p class='title'>{{ $image->name }}</p>
@if(!empty($image->description))
<p class='description'>{{ $image->description }}</p>
@endif
@auth
<div class="buttons-container">
@if ($liked)
<button class="submit-btn like liked" id='{{ $image->id }}'><i class="fas fa-check"></i> Liked</button>
@else
<button class="submit-btn like" id='{{ $image->id }}'><i class="far fa-thumbs-up"></i> Like</button>
@endif
@if(Auth::id() === $image->user_id || Auth::user()->hasRole('Admin'))
<a class='edit-btn edit' href="{{ route('updateArtworkView', $image->id) }}"><i class="far fa-edit"></i> Edit</a>
@endif
</div>
@endauth
<div class="stats-container">
<p class='likes-count'><i class="far fa-thumbs-up fa-fw"></i>{{ $numberOfLikes }} Likes</p>
<p><i class="far fa-eye fa-fw"></i>{{ $image->views }} Views</p>
<p class='comments-count'><i class="far fa-comments fa-fw"></i>{{ $commentsCount }} Comments</p>
<p><i class="fas fa-file-download fa-fw"></i>
<a href="{{url("storage/uploads/images/specificImages/".$image->image_file_name)}}" download="{{ $image->name }}">Download</a>
</p>
</div>
@if(count($tags) > 0)
<div class='tags-container'>
<p><i class="fas fa-tags fa-fw"></i>Tags</p>
<div>
@foreach($tags as $tag)
<a class='image-tag' href="{{url('search?q='.$tag->name)}}">{{ $tag->name }}</a>
@endforeach
</div>
</div>
@endif
@if(count($recentImages) > 0)
<p class='more-by-author'>More images by<a href='{{ route('profile', $author->username) }}'>
{{ $author->username }}<img class='profile-picture' src='{{url("storage/uploads/profile_pictures/edited/".$author->image_file_name)}}'>
</a></p>
<div class="gallery-container">
@foreach($recentImages as $recentImage)
<a class="gallery-element" href='{{ route('specificImage', $recentImage->id) }}'>
<img class='responsive-image' src='{{url("storage/uploads/images/miniImages/".$recentImage->image_file_name)}}' alt='Random image' />
</a>
@endforeach
</div>
@endif
@if(count($similarImages) > 0)
<p class='similar-from-category'>Similar images from<a href='{{ route('specificCategory', $image->category->name)}}'>
{{ $image->category->name }}<img class='profile-picture' src='{{url("storage/uploads/categories/thumbnails/".$image->category->image_file_name)}}'>
</a></p>
<div class="gallery-container">
@foreach($similarImages as $similarImage)
<a class="gallery-element" href='{{ route('specificImage', $similarImage->id) }}'>
<img class='responsive-image' src='{{url("storage/uploads/images/miniImages/".$similarImage->image_file_name)}}' alt='Random image' />
</a>
@endforeach
</div>
@endif
@auth
<form class='comment-form' method='POST' action=''>
<textarea class='comment-textarea' name='comment'></textarea>
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
<input type="hidden" name="image_id" value="{{ $image->id }}">
<button class='submit-btn post-comment' type='submit' name='commentSubmit'><i class="far fa-comment"></i> Comment</button>
</form>
@endauth
@if(count($comments) > 0)
<div class='comments-container'>
@foreach($comments as $comment)
<div class="comment-flexbox">
<div class="comment-container">
<a href='{{ route('profile', $comment->user->username) }}'>
<img class='comment-picture' src='{{ url("storage/uploads/profile_pictures/edited/".$comment->user->image_file_name )}}'>
</a>
</div>
<div class="comment-info-container">
<a href='{{ route('profile', $comment->user->username) }}'>{{ $comment->user->username }}</a>
<p>{{ $comment->comment }}</p>
</div>
<div class="comment-actions-container">
@auth
@if(Auth::id() === $comment->user->id || Auth::user()->hasRole('Admin'))
<i class="fas fa-times delete-comment" data-id="{{ $comment->id }}" data-image="{{ $image->id }}"></i>
@endif
@endauth
</div>
</div>
@endforeach
</div>
@endif
</div>
</div>
<script>
var token = '{{ Session::token() }}';
var urlComment = '{{ route('comment') }}';
var urlDeleteComment = '{{ route('deleteComment') }}';
var urlLike = '{{ route('likeArtwork') }}';
</script>
@endsection
@extends('layouts.app'))
@节(“内容”)
@foreach($subImage作为$subImage)
@endforeach
{{$image->name}
@如果(!空($image->description))
{{$image->description}
@恩迪夫
@认证
@如果($喜欢)
喜欢
@否则
喜欢
@恩迪夫
@如果(Auth::id()==$image->user_id | | Auth::user()->hasRole('Admin'))
@恩迪夫
@endauth
{{$numberOfLikes}likes
{{$image->views}}视图
{{$commentscont}comments
@如果(计数($tags)>0)
标签
@foreach($tags作为$tag)
@endforeach
@恩迪夫
@如果(计数($recentImages)>0)
@foreach($recentImages作为$recentImage)
@endforeach
@恩迪夫
@如果(计数($similarImages)>0)
来自的相似图像
@foreach($similarImages作为$similarImage)
@endforeach
@恩迪夫
@认证
议论
@endauth
@如果(计数($comments)>0)
@foreach($comments作为$comment)
{{$comment->comment}
@认证
@如果(Auth::id()==$comment->user->id | | Auth::user()->hasRole('Admin'))
@恩迪夫
@endauth
@endforeach
@恩迪夫
var-token='{{Session::token()}}';
var urlcoment='{route('comment')}}';
var urldeletecoment='{{route('deletecoment')}}';
var urlike='{{route('likeArtwork')}}';
@端部
出现此问题的原因是您的php 7.3版尚不受支持
所以我可以建议检查以下GitHub线程。
您可以更改此文件vendor/laravel/framework/src/illumb/Database/Query/Builder.php
发件人:
致:
我刚刚通过将laravel更新为5.5.48解决了这个问题。你能举个控制器的例子吗?您使用的是哪个版本的laravel/framework?您的laravel版本是什么?您使用的是哪个版本?我的Laravel版本是5.5.41,我的PHP版本是7.3.7。我马上要用查看代码更新我的帖子。$this->wheres[]=compact('type','operator','query','boolean');没有$Operator银行解决了这个问题。出于好奇,像这样修改Laravel文件是不是不好的做法?当然是这样,每个composer更新/安装都会撤销此更改,您将返回到一开始就出现相同的错误。编辑Laravel核心文件是一种非常糟糕的做法。
$this->wheres[] = compact('type', 'operator', 'query', 'boolean');
$this->wheres[] = compact('type', 'query', 'boolean');