【发布时间】:2021-12-11 19:59:29
【问题描述】:
所以我正在尝试为我的 imageshare 制作一个类似的系统。 为此,我尝试使用 overtrue 中的“Laravel Follow”,但这给我带来了问题。
每次我尝试使用他在 GitHub 页面中所说的功能时,它总是给我“调用未定义的方法 App\Models\Photo::needsToApproveFollowRequests()”。
这是我的 User.php
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Contracts\Auth\CanResetPassword;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Overtrue\LaravelFollow\Followable;
class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens, HasFactory, Notifiable, Followable;
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = [
'firstName',
'lastName',
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
这是我尝试使用的控制器中的功能:
public function getSnatch($id) {
//Let's try to find the image from database first
$image = Photo::find($id);
if(!$image) {
abort(404);
}
$imageThumb = Photo::find($id)->paginate(1);
$user = User::find($image->user);
$currentUser = User::find(auth()->user()->id);
// $user = User::where('id', $userID)->first();
$lastId = Photo::where('id', '<', $image->id)->max('id');
$nextId = Photo::where('id', '>', $image->id)->min('id');
// $nextPageNumber = $image->id + 1;
$maxId = Photo::find($id)->max('id');
$minId = Photo::find($id)->min('id');
// $imageCount = count(DB::table('photos')->get());
// ddd($nextId);
$likeImage = $currentUser->toggleFollow($image);
$totalLikes = $image->followers();
if ($lastId < $minId) {
$lastId = $maxId;
}
if ($nextId === NULL) {
$nextId = $minId;
}
//If found, we load the view and pass the image info asparameter, else we redirect to main page with errormessage
if($image) {
return View::make('tpl.permalink')
->with('image', $image)
->with('lastId', $lastId)
->with('nextId', $nextId)
->with('user', $user)
->with('imageThumb', $imageThumb)
->with('currentUser', $currentUser)
->with('likeImage', $likeImage)
->with('totalLikes', $totalLikes);
} else {
return Redirect::to('/')->with('error','Image not found');
}
}
composer 中的所有内容都安装得很好。 我也试过删除vendor文件夹,清除composer的缓存,重新安装composer,还是不行。
【问题讨论】:
标签: laravel