1

MessageController.php

public function getMessages(){
    $messages = Message::all();

    return view('messages')->with('messages','$messages');
}

Routes/web.php

Route::get('/messages','MessagesController@getMessages');

messages.blade.php

@extends('layout.app')

@section('content')

    <h1>Messages</h1>

    @if(count($messages) > 0)
        @foreach($messages as $message)
            <ul class="list-group">
                <li class="list-group-item">Name: {‌{$message->name}}</li>
                <li class="list-group-item">Email: {‌{$message->email}}</li>
                <li class="list-group-item">Message: {‌{$message->message}}</li>
            </ul>
        @endforeach
    @endif

@endsection

Inside the layout folder / app.blade.php is my layout template blade.

The error message:

ErrorException (E_ERROR)

count(): Parameter must be an array or an object that implements Countable (View: C:\xampp\htdocs\basicwebsite\resources\views\messages.blade.php)

dhilt
  • 18,707
  • 8
  • 70
  • 85
  • 1
    Possible duplicate of [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – Devon Bessemer Oct 10 '18 at 21:07
  • @Devon I don't think the OP realized the quotes. This isn't a duplicate per se – Paras Oct 10 '18 at 21:08

1 Answers1

2

The error is you are passing a string, not a variable

Replace with('messages','$messages') with with('messages', $messages). Notice the missing quotes in second argument.

Paras
  • 9,258
  • 31
  • 55
  • yes sir before 10 minutes i found it, its fix my problem you are fabulous . thanks –  Oct 10 '18 at 21:17
  • sir i have a question i develop my website using wordpress (www.freeartflow.com) now im learning the laravel framwork to build like these websites , its a monthly payment membership for graphic resources (2d-3d-video temp) . how can i learn to make this steps (recurrent membership) in the laravel ... can i do it ! and where ! I will be very grateful to you ..... also can i create contributors like www.freepik.com ....... many thanks –  Oct 10 '18 at 21:21
  • Check out [Laravel Cashier](https://laravel.com/docs/5.7/billing) for subscription payments and possibly [Laravel Spark](https://spark.laravel.com) for SaaS projects. Cheers! – Paras Oct 10 '18 at 21:25
  • can also make the payment with paypal rather than stripe –  Oct 10 '18 at 21:28
  • Yes, Braintree supports Paypal and Cashier supports Braintree – Paras Oct 10 '18 at 21:29
  • thank you sir very very much ,have a good day –  Oct 10 '18 at 21:33