[英]Came back to a Laravel project that I hadn't touched in months and received a “compact(): Undefined variable: operator” error
I'm receiving this error whenever I attempt to visit a certain view.每当我尝试访问某个视图时,我都会收到此错误。 Sadly the error doesn't make it any clear why is this happening.
可悲的是,该错误并没有说明为什么会发生这种情况。 The project worked fine a month ago and I don't think I've made any changes since then but when I checked it out today, I got the error.
该项目在一个月前运行良好,从那时起我认为我没有进行任何更改,但是当我今天检查它时,我得到了错误。
Any ideas why this might be happening?任何想法为什么会发生这种情况?
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"
The view where this is happening:发生这种情况的视图:
@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
This issue occurs because of your php version 7.3 isn't yet supported.出现此问题的原因是您的 php 版本 7.3 尚不受支持。
So I can suggest check following GitHub thread.所以我可以建议检查以下 GitHub 线程。 https://github.com/laravel/framework/issues/26936
https://github.com/laravel/framework/issues/26936
You can change this file.您可以更改此文件。
vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php
From:从:
$this->wheres[] = compact('type', 'operator', 'query', 'boolean');
To:至:
$this->wheres[] = compact('type', 'query', 'boolean');
I just solved this by updating laravel to 5.5.48.我刚刚通过将 laravel 更新到 5.5.48 解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.