davy_yg
338
4
Laravel

Trying to get property of non-object

Posted 2 years ago by davy_yg

ErrorException in 03007f072e31a098b220ef17e87d73f3 line 1417: Trying to get property of non-object (View: C:\xampp\htdocs\soulfy_repo\framework\resources\views\home.blade.php) (View: C:\xampp\htdocs\soulfy_repo\framework\resources\views\home.blade.php)

I wonder why the error appears.

HomeController.php

 public function getBackgroundTheme()
 {

    $query = DB::table('theme_background');//->paginate(4);

    if (request()->has('menu')) {
        $theme = DB::table('kategori_name')->where('kategori_theme', request('menu'))->first();

        $query = $query->where('kategori_id', $theme->kategori_id);
    }

    $model = $query->get();

    
    return view('soulfy.setting', [
        'themes'=>$model,
        'user' => auth()->user(),
    ]);


    // return redirect('/home/setting' . 
 }

setting.blade.php

       <form action="{{URL::to('/home/theme')}}" method="post"> 
                                    <span class="setting-name">THEME</span>

                                    <!-- <form method="POST" action="/posts"> -->
                                    {{ csrf_field() }}  
                                    <span class="setting-value center">

                                    <select name="menu">
                                        <option value="Music">Music</option>
                                        <option value="Tour & Travel">Tour & Travel</option>
                                        <option value="Landscape">Landscape</option>
                                        <option value="Lifestyle">Lifestyle</option>
                                        <option value="Office">Office</option>
                                        <option value="Hobby">Hobby</option>
                                        <option value="Building">Building</option>
                                    </select>


                                    <input type="submit" value="Submit">                                        
                                    <br><br>

                                    </span>

                                    
                                    
                                    @if(isset($themes))
                                    @foreach($themes as $m)

                                    <tr><img width="100px" height="100px" src="{{url('/')}}/uploads/theme/{{$m->pic_name}}.jpg"/></tr>
                                    

                                    @endforeach
                                    @endif


                                    <br><br><br>    
                                    
                                    </form>

After pressing the submit form, I expect to see a list of pictures of the selected themes. This time I see the above error message instead of seeing pictures of the selected themes.

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