Laravel not getting info out of database, displays erros











up vote
0
down vote

favorite












Sorry, I'm new to developing on Laravel. I'm trying to show info contained in the database on my page. But it can't find the variable holding all the data. I can see the info in Tinker, but i can't seem to deplay is.



I posted some pictures so you can have a look. I'd love to hear your feedback.



Images: https://imgur.com/a/zLSqSDG



Code:



Route:



<?php

Route::get('/', function () {
return view('index');
});

Route::resource('complaints', 'ComplaintController');


Controller:



<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppComplaint;

class ComplaintController extends Controller
{
/**
* Display a listing of the resource.
*
* @return IlluminateHttpResponse
*/
public function index()
{
$complaints = Complaint::all();

return view('index', compact('complaints'));
}


Blade:



@extends('layout')

@section('title','Welcome')

@section('content')

{{-- @foreach ($complaints as $complaint)
<h1>{{ $complaint->title }}</h1>
<p>{{ $complaint->body }}</p>
@endforeach --}}

{{ $complaints }}


@endsection









share|improve this question




















  • 3




    It would be much easier to help if you posted your code as text rather than images.
    – M̨̹̖̱̠̭̠̱̘͌̓ͬͫa̧͔͇̗͖͖͑ͭ͝t̆͗̊ͫt
    Nov 12 at 10:48










  • Add code here too, which contains route, controller and blade file.
    – Kamal Paliwal
    Nov 12 at 10:48










  • your code is ok , did you set your database config in .env ?
    – amini.swallow
    Nov 12 at 10:55










  • Thank you for your feedback, Posting 3 different code tags does not work on stackoverflow, so i made a Pastebin for you to take a look: pastebin.com/dWv6YxEq The database is correctly configured because the POST method already works for adding new items into DB.
    – STechmo
    Nov 12 at 11:22






  • 1




    your route is /complaints but you visited / in the pictures
    – AmirhosseinDZ
    Nov 12 at 11:25















up vote
0
down vote

favorite












Sorry, I'm new to developing on Laravel. I'm trying to show info contained in the database on my page. But it can't find the variable holding all the data. I can see the info in Tinker, but i can't seem to deplay is.



I posted some pictures so you can have a look. I'd love to hear your feedback.



Images: https://imgur.com/a/zLSqSDG



Code:



Route:



<?php

Route::get('/', function () {
return view('index');
});

Route::resource('complaints', 'ComplaintController');


Controller:



<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppComplaint;

class ComplaintController extends Controller
{
/**
* Display a listing of the resource.
*
* @return IlluminateHttpResponse
*/
public function index()
{
$complaints = Complaint::all();

return view('index', compact('complaints'));
}


Blade:



@extends('layout')

@section('title','Welcome')

@section('content')

{{-- @foreach ($complaints as $complaint)
<h1>{{ $complaint->title }}</h1>
<p>{{ $complaint->body }}</p>
@endforeach --}}

{{ $complaints }}


@endsection









share|improve this question




















  • 3




    It would be much easier to help if you posted your code as text rather than images.
    – M̨̹̖̱̠̭̠̱̘͌̓ͬͫa̧͔͇̗͖͖͑ͭ͝t̆͗̊ͫt
    Nov 12 at 10:48










  • Add code here too, which contains route, controller and blade file.
    – Kamal Paliwal
    Nov 12 at 10:48










  • your code is ok , did you set your database config in .env ?
    – amini.swallow
    Nov 12 at 10:55










  • Thank you for your feedback, Posting 3 different code tags does not work on stackoverflow, so i made a Pastebin for you to take a look: pastebin.com/dWv6YxEq The database is correctly configured because the POST method already works for adding new items into DB.
    – STechmo
    Nov 12 at 11:22






  • 1




    your route is /complaints but you visited / in the pictures
    – AmirhosseinDZ
    Nov 12 at 11:25













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Sorry, I'm new to developing on Laravel. I'm trying to show info contained in the database on my page. But it can't find the variable holding all the data. I can see the info in Tinker, but i can't seem to deplay is.



I posted some pictures so you can have a look. I'd love to hear your feedback.



Images: https://imgur.com/a/zLSqSDG



Code:



Route:



<?php

Route::get('/', function () {
return view('index');
});

Route::resource('complaints', 'ComplaintController');


Controller:



<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppComplaint;

class ComplaintController extends Controller
{
/**
* Display a listing of the resource.
*
* @return IlluminateHttpResponse
*/
public function index()
{
$complaints = Complaint::all();

return view('index', compact('complaints'));
}


Blade:



@extends('layout')

@section('title','Welcome')

@section('content')

{{-- @foreach ($complaints as $complaint)
<h1>{{ $complaint->title }}</h1>
<p>{{ $complaint->body }}</p>
@endforeach --}}

{{ $complaints }}


@endsection









share|improve this question















Sorry, I'm new to developing on Laravel. I'm trying to show info contained in the database on my page. But it can't find the variable holding all the data. I can see the info in Tinker, but i can't seem to deplay is.



I posted some pictures so you can have a look. I'd love to hear your feedback.



Images: https://imgur.com/a/zLSqSDG



Code:



Route:



<?php

Route::get('/', function () {
return view('index');
});

Route::resource('complaints', 'ComplaintController');


Controller:



<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppComplaint;

class ComplaintController extends Controller
{
/**
* Display a listing of the resource.
*
* @return IlluminateHttpResponse
*/
public function index()
{
$complaints = Complaint::all();

return view('index', compact('complaints'));
}


Blade:



@extends('layout')

@section('title','Welcome')

@section('content')

{{-- @foreach ($complaints as $complaint)
<h1>{{ $complaint->title }}</h1>
<p>{{ $complaint->body }}</p>
@endforeach --}}

{{ $complaints }}


@endsection






php laravel tinker






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 13:08









blue-phoenox

3,81681440




3,81681440










asked Nov 12 at 10:45









STechmo

32




32








  • 3




    It would be much easier to help if you posted your code as text rather than images.
    – M̨̹̖̱̠̭̠̱̘͌̓ͬͫa̧͔͇̗͖͖͑ͭ͝t̆͗̊ͫt
    Nov 12 at 10:48










  • Add code here too, which contains route, controller and blade file.
    – Kamal Paliwal
    Nov 12 at 10:48










  • your code is ok , did you set your database config in .env ?
    – amini.swallow
    Nov 12 at 10:55










  • Thank you for your feedback, Posting 3 different code tags does not work on stackoverflow, so i made a Pastebin for you to take a look: pastebin.com/dWv6YxEq The database is correctly configured because the POST method already works for adding new items into DB.
    – STechmo
    Nov 12 at 11:22






  • 1




    your route is /complaints but you visited / in the pictures
    – AmirhosseinDZ
    Nov 12 at 11:25














  • 3




    It would be much easier to help if you posted your code as text rather than images.
    – M̨̹̖̱̠̭̠̱̘͌̓ͬͫa̧͔͇̗͖͖͑ͭ͝t̆͗̊ͫt
    Nov 12 at 10:48










  • Add code here too, which contains route, controller and blade file.
    – Kamal Paliwal
    Nov 12 at 10:48










  • your code is ok , did you set your database config in .env ?
    – amini.swallow
    Nov 12 at 10:55










  • Thank you for your feedback, Posting 3 different code tags does not work on stackoverflow, so i made a Pastebin for you to take a look: pastebin.com/dWv6YxEq The database is correctly configured because the POST method already works for adding new items into DB.
    – STechmo
    Nov 12 at 11:22






  • 1




    your route is /complaints but you visited / in the pictures
    – AmirhosseinDZ
    Nov 12 at 11:25








3




3




It would be much easier to help if you posted your code as text rather than images.
– M̨̹̖̱̠̭̠̱̘͌̓ͬͫa̧͔͇̗͖͖͑ͭ͝t̆͗̊ͫt
Nov 12 at 10:48




It would be much easier to help if you posted your code as text rather than images.
– M̨̹̖̱̠̭̠̱̘͌̓ͬͫa̧͔͇̗͖͖͑ͭ͝t̆͗̊ͫt
Nov 12 at 10:48












Add code here too, which contains route, controller and blade file.
– Kamal Paliwal
Nov 12 at 10:48




Add code here too, which contains route, controller and blade file.
– Kamal Paliwal
Nov 12 at 10:48












your code is ok , did you set your database config in .env ?
– amini.swallow
Nov 12 at 10:55




your code is ok , did you set your database config in .env ?
– amini.swallow
Nov 12 at 10:55












Thank you for your feedback, Posting 3 different code tags does not work on stackoverflow, so i made a Pastebin for you to take a look: pastebin.com/dWv6YxEq The database is correctly configured because the POST method already works for adding new items into DB.
– STechmo
Nov 12 at 11:22




Thank you for your feedback, Posting 3 different code tags does not work on stackoverflow, so i made a Pastebin for you to take a look: pastebin.com/dWv6YxEq The database is correctly configured because the POST method already works for adding new items into DB.
– STechmo
Nov 12 at 11:22




1




1




your route is /complaints but you visited / in the pictures
– AmirhosseinDZ
Nov 12 at 11:25




your route is /complaints but you visited / in the pictures
– AmirhosseinDZ
Nov 12 at 11:25












4 Answers
4






active

oldest

votes

















up vote
0
down vote



accepted










You are not routing to the correct function in your controller. Try this



Route::resource('complaints', 'ComplaintController@index');





share|improve this answer





















  • This solved my Issue, thank you very much!
    – STechmo
    Nov 12 at 21:48


















up vote
0
down vote













Try it with another syntax like below:



public function index() {
$complaints = Complaint::all();
return view('index')->with(compact('complaints'));
}


or



 public function index() {
$complaints = Complaint::all();
return view('index')->with('complaints', $complaints);
}





share|improve this answer




























    up vote
    0
    down vote













    As @amirhosseindz said

    When you're visiting this url : http://127.0.0.1:8000/complaints it will work because you're hitting



    Route::resource('complaints', 'ComplaintController');



    But when you visit this url : http://127.0.0.1:8000



    you're hitting this action:



    Route::get('/', function () {
    return view('index');
    });


    where $complaints doesn't exists






    share|improve this answer





















    • Thank you, the view did not include the complaints, thats why they did not show up.
      – STechmo
      Nov 12 at 21:50


















    up vote
    0
    down vote













    You should try this:



    Your Controller



    public function index() {
    $complaints = Complaint::all();
    return view('index',compact('complaints'));
    }


    Your View (index.blade.php)



    @extends('layout')

    @section('title','Welcome')

    @section('content')

    @if(isset($complaints))
    @foreach ($complaints as $complaint)
    <h1>{{ $complaint->title }}</h1>
    <p>{{ $complaint->body }}</p>
    @endforeach
    @endif


    @endsection





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260498%2flaravel-not-getting-info-out-of-database-displays-erros%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      You are not routing to the correct function in your controller. Try this



      Route::resource('complaints', 'ComplaintController@index');





      share|improve this answer





















      • This solved my Issue, thank you very much!
        – STechmo
        Nov 12 at 21:48















      up vote
      0
      down vote



      accepted










      You are not routing to the correct function in your controller. Try this



      Route::resource('complaints', 'ComplaintController@index');





      share|improve this answer





















      • This solved my Issue, thank you very much!
        – STechmo
        Nov 12 at 21:48













      up vote
      0
      down vote



      accepted







      up vote
      0
      down vote



      accepted






      You are not routing to the correct function in your controller. Try this



      Route::resource('complaints', 'ComplaintController@index');





      share|improve this answer












      You are not routing to the correct function in your controller. Try this



      Route::resource('complaints', 'ComplaintController@index');






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 12 at 13:16









      Mike Miller

      2,06611220




      2,06611220












      • This solved my Issue, thank you very much!
        – STechmo
        Nov 12 at 21:48


















      • This solved my Issue, thank you very much!
        – STechmo
        Nov 12 at 21:48
















      This solved my Issue, thank you very much!
      – STechmo
      Nov 12 at 21:48




      This solved my Issue, thank you very much!
      – STechmo
      Nov 12 at 21:48












      up vote
      0
      down vote













      Try it with another syntax like below:



      public function index() {
      $complaints = Complaint::all();
      return view('index')->with(compact('complaints'));
      }


      or



       public function index() {
      $complaints = Complaint::all();
      return view('index')->with('complaints', $complaints);
      }





      share|improve this answer

























        up vote
        0
        down vote













        Try it with another syntax like below:



        public function index() {
        $complaints = Complaint::all();
        return view('index')->with(compact('complaints'));
        }


        or



         public function index() {
        $complaints = Complaint::all();
        return view('index')->with('complaints', $complaints);
        }





        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          Try it with another syntax like below:



          public function index() {
          $complaints = Complaint::all();
          return view('index')->with(compact('complaints'));
          }


          or



           public function index() {
          $complaints = Complaint::all();
          return view('index')->with('complaints', $complaints);
          }





          share|improve this answer












          Try it with another syntax like below:



          public function index() {
          $complaints = Complaint::all();
          return view('index')->with(compact('complaints'));
          }


          or



           public function index() {
          $complaints = Complaint::all();
          return view('index')->with('complaints', $complaints);
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 12:14









          thenextbillionaire

          1




          1






















              up vote
              0
              down vote













              As @amirhosseindz said

              When you're visiting this url : http://127.0.0.1:8000/complaints it will work because you're hitting



              Route::resource('complaints', 'ComplaintController');



              But when you visit this url : http://127.0.0.1:8000



              you're hitting this action:



              Route::get('/', function () {
              return view('index');
              });


              where $complaints doesn't exists






              share|improve this answer





















              • Thank you, the view did not include the complaints, thats why they did not show up.
                – STechmo
                Nov 12 at 21:50















              up vote
              0
              down vote













              As @amirhosseindz said

              When you're visiting this url : http://127.0.0.1:8000/complaints it will work because you're hitting



              Route::resource('complaints', 'ComplaintController');



              But when you visit this url : http://127.0.0.1:8000



              you're hitting this action:



              Route::get('/', function () {
              return view('index');
              });


              where $complaints doesn't exists






              share|improve this answer





















              • Thank you, the view did not include the complaints, thats why they did not show up.
                – STechmo
                Nov 12 at 21:50













              up vote
              0
              down vote










              up vote
              0
              down vote









              As @amirhosseindz said

              When you're visiting this url : http://127.0.0.1:8000/complaints it will work because you're hitting



              Route::resource('complaints', 'ComplaintController');



              But when you visit this url : http://127.0.0.1:8000



              you're hitting this action:



              Route::get('/', function () {
              return view('index');
              });


              where $complaints doesn't exists






              share|improve this answer












              As @amirhosseindz said

              When you're visiting this url : http://127.0.0.1:8000/complaints it will work because you're hitting



              Route::resource('complaints', 'ComplaintController');



              But when you visit this url : http://127.0.0.1:8000



              you're hitting this action:



              Route::get('/', function () {
              return view('index');
              });


              where $complaints doesn't exists







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 12 at 12:27









              cbaconnier

              9751621




              9751621












              • Thank you, the view did not include the complaints, thats why they did not show up.
                – STechmo
                Nov 12 at 21:50


















              • Thank you, the view did not include the complaints, thats why they did not show up.
                – STechmo
                Nov 12 at 21:50
















              Thank you, the view did not include the complaints, thats why they did not show up.
              – STechmo
              Nov 12 at 21:50




              Thank you, the view did not include the complaints, thats why they did not show up.
              – STechmo
              Nov 12 at 21:50










              up vote
              0
              down vote













              You should try this:



              Your Controller



              public function index() {
              $complaints = Complaint::all();
              return view('index',compact('complaints'));
              }


              Your View (index.blade.php)



              @extends('layout')

              @section('title','Welcome')

              @section('content')

              @if(isset($complaints))
              @foreach ($complaints as $complaint)
              <h1>{{ $complaint->title }}</h1>
              <p>{{ $complaint->body }}</p>
              @endforeach
              @endif


              @endsection





              share|improve this answer

























                up vote
                0
                down vote













                You should try this:



                Your Controller



                public function index() {
                $complaints = Complaint::all();
                return view('index',compact('complaints'));
                }


                Your View (index.blade.php)



                @extends('layout')

                @section('title','Welcome')

                @section('content')

                @if(isset($complaints))
                @foreach ($complaints as $complaint)
                <h1>{{ $complaint->title }}</h1>
                <p>{{ $complaint->body }}</p>
                @endforeach
                @endif


                @endsection





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You should try this:



                  Your Controller



                  public function index() {
                  $complaints = Complaint::all();
                  return view('index',compact('complaints'));
                  }


                  Your View (index.blade.php)



                  @extends('layout')

                  @section('title','Welcome')

                  @section('content')

                  @if(isset($complaints))
                  @foreach ($complaints as $complaint)
                  <h1>{{ $complaint->title }}</h1>
                  <p>{{ $complaint->body }}</p>
                  @endforeach
                  @endif


                  @endsection





                  share|improve this answer












                  You should try this:



                  Your Controller



                  public function index() {
                  $complaints = Complaint::all();
                  return view('index',compact('complaints'));
                  }


                  Your View (index.blade.php)



                  @extends('layout')

                  @section('title','Welcome')

                  @section('content')

                  @if(isset($complaints))
                  @foreach ($complaints as $complaint)
                  <h1>{{ $complaint->title }}</h1>
                  <p>{{ $complaint->body }}</p>
                  @endforeach
                  @endif


                  @endsection






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 12 at 12:33









                  Saurabh Dhariwal

                  1,01812




                  1,01812






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260498%2flaravel-not-getting-info-out-of-database-displays-erros%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Xamarin.iOS Cant Deploy on Iphone

                      Glorious Revolution

                      Dulmage-Mendelsohn matrix decomposition in Python