Попытка получить доступ к смещению массива по значению типа null (View: /app/resources/views/products/productView.blade.php) - PullRequest
0 голосов
/ 31 марта 2020

Может кто-нибудь помочь мне с этой ошибкой? мой проект работает нормально на локальном сервере, но когда я пу sh к героку, это дает мне ошибку ниже. Любая помощь?

Я использую php version 7.3.7 и laravel version 6.18.3, также я впервые использую heroku. Я загрузил код

imagefilename))) }}">

Контроллер продукта

public function showProductDescription($id) {

// echo $id;

$category = Category::all()->sortBy('category_name');
// $category->category_name;
$userLikes = new Comment();

$products = Product::where('id', $id)->get();
$comments = Comment::where('product_id', $id)->get();

$commentCount = Comment::where('product_id', $id)->get('comments')->count(); 
$pag = Comment::where('product_id', $id)->paginate(10);

if(Auth::check()) {
    $carts = Cart::where('user_id', Auth::user()->id)
                ->where('active', '=', '1')->count();

    $findFollow = Following::where('user_id', Auth::user()->id)
                    ->where('followed_to', $id)->first();

    $findLikes = Comment::where('user_id', Auth::user()->id)
                    ->where('product_id', $id)->first();


                    // dd(Product::all());
                    // dd($findFollow);
                    // dd($findLikes);
                    // dd($pag);
                    // dd($commentCount);
                    // die();

    return view('products.productView', compact('products', 'comments', 'pag', 'commentCount', 'carts', 'findFollow', 'category', 
                    'userLikes', 'findLikes'));

} else {
    $carts = Cart::where('active', '=', '1')->count();

    $findFollow = '';

    $findLikes = '';

                    // dd(Product::all());
                    // dd($findFollow);
                    // dd($findLikes);
                    // dd($pag);
                    // dd($commentCount);
                    // die();

    return view('products.productView', compact('products', 'comments', 'pag', 'commentCount', 'carts', 'findFollow', 'category', 
                                            'userLikes', 'findLikes'));
}


}

public function likedProduct($id) {

if(Auth::check()) {

    $product = Product::where('id', $id)->first();

    $userLikes = new Comment();
    $userLikes->user_id = Auth::user()->id;
    $userLikes->product_id = $product->id;
    $userLikes->likes = '1';

    $userLikes->save();

    if($product->total_likes == 0) {
        $product->total_likes = 1;
    } else {
        $product->total_likes = $product->total_likes + 1;
    }

    $product->save();
    return redirect()->action('ProductController@showProductDescription', ['id' => $id]);
} else {
    Session::flash("message", "OOPS! You dont have permission to upload the items. Please register first.");
    return redirect("/register-user");
}
}

public function unlikeProduct($id) {

if(Auth::check()) {
    $comments = Comment::where('user_id', Auth::user()->id)
                            ->where('product_id', $id)->delete();


    $product = Product::where('id', $id)->get('total_likes')->count();

    // echo $product;
    // die();

    if($product>0) {
        $productLikes = Product::where('id', $id)->first();
        $productLikes->total_likes = $productLikes->total_likes - 1;
        $productLikes->save();
    }

    // Session::flash("message", "OOPS! You dont have permission to upload the items. Please register first.");
    return redirect()->action('ProductController@showProductDescription', ['id' => $id]);
} else {
    Session::flash("message", "OOPS! You dont have permission to upload the items. Please register first.");
    return redirect("/register-user");
}


}
public function productComment($id) {
if(Auth::check()) {

    $c = Input::get('comment');

    $product = Product::where('id', $id)->first();

    $user_comments = new Comment();
    $user_comments->user_id = Auth::user()->id;
    $user_comments->product_id = $product->id;
    $user_comments->comments = $c;

    $user_comments->save();

    if($product->total_comments == 0) {
        $product->total_comments = 1;
    } else {
        $product->total_comments = $product->total_comments + 1;
    }

    $product->save();

    Session::flash('message', 'Your comment has been added successfully');
    return redirect()->action('ProductController@showProductDescription', ['id' => $id]);


}  else {
    Session::flash("message", "OOPS! You dont have permission to upload the items. Please register first.");
    return redirect("/register-user");
}     
}

Я обновил код, поэтому, если вы можете помочь определить проблему, так как я не смог определить проблема за последние полтора дня, и мне нужно исправить это

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...