3 weeks ago

How to make it visible for non members

Posted 3 weeks ago by webfuelcode

A single post page shows error

Trying to get property 'id' of non-object

The error shows the line where if the statement is placed which @if (auth()->user()->id == $link->user_id) in the below file.


    <div class="container">
        {{--Site messages--}}
        {{--Site messages ends--}}
        <div class="clearfix">
            <a href="{{ route('link.index') }}" class="btn btn-warning float-left">List</a>
            <a href="{{ route('link.create') }}" class="btn btn-primary float-right">Add</a>
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card border-0">
                    <h4 class="card-header">
                        {{ $link->title }}
                    <div class="card-body">
                        <p class="card-text">
                            {{ $link->description }}
                        <div class="card-text">
                            {{ $link->url }}
                        @if (auth()->user()->id == $link->user_id)
                            <div class="card-link float-right">
                                <div class="actions form-inline">
                                    <a href="{{route('link.edit', $link->id)}}" class="btn btn-info btn-sm badge form-group m-1">Edit</a>

                                    <form action="{{route('link.destroy', $link->id)}}" method="POST" class="form-group">
                                        <button type="submit" class="btn btn-danger badge m-1">Delete</button>

Controller file is here

function __construct()
        return $this->middleware('auth')->except('index', 'show');
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index()
        $links = Link::paginate(5);
        return view('list', compact('links'));

	public function show(link $link)
        return view('single', compact('link'));

Please sign in or create an account to participate in this conversation.