0

I have got Laravel installed and I am trying to fetch ANY data from the SQL Server database but i keep having the same problem all the time and I am getting so frustrated because I either just don't know what I am doing or I am doing it wrong.

I've got my database connection set up after a lot of hassle with ODBC SQL Drivers for Windows. Now in my welcome.blade.php I want to fetch data from my database but everytime i try to get any data i get this error:

Fatal error: Class 'Illuminate\Support\Facades\DB' not found in C:\xampp\htdocs\resources\views\welcome.blade.php on line 9

Now I only got these two lines in my code that should fetch (I GUESS) the data:

<?php
    $Booking = \Illuminate\Support\Facades\DB::table('fmsStage.dbo.Booking')->get();
    var_dump($Booking);
?>

But instead it gives me that error. And I've tried using \DB::table and also tried using just the table itself \DB::table('Booking') and also with the table prefix \DB::table('dbo.Booking') but it won't even find the whole DB class. But what am I doing wrong, I don't get it at all.

When i try to add

use DB;

It gives me another error/warning:

Warning: The use statement with non-compound name 'DB' has no effect in C:\xampp\htdocs\resources\views\welcome.blade.php on line 9

UPDATE: I have now created the model Booking to get data from booking. But now when i use

use App\Booking;
$booking = App\Booking::all();
foreach($booking as $bookings) {
    echo $bookings->agent;
}

It stills gives me an error on the freaking USE part...

Fatal error: Class 'app\Booking' not found in C:\xampp\htdocs\resources\views\welcome.blade.php on line 10

Thank you in advance

4
  • Try $data = TABLENAME::all(); change table name with the name of your model Commented Nov 10, 2016 at 8:50
  • I don't have a model? What does a model do? Commented Nov 10, 2016 at 8:52
  • Try Snowno answer below but like this use Illuminate\Support\Facades\DB as DB; Commented Nov 10, 2016 at 8:56
  • I did as snowno said and then used that with what you just said. It still gives me this error: Fatal error: Class 'Illuminate\Support\Facades\DB' not found in C:\xampp\htdocs\resources\views\welcome.blade.php on line 12 Commented Nov 10, 2016 at 8:59

1 Answer 1

2

try this:

use \Illuminate\Support\Facades\DB;
$data = DB::table("tablename")->get();
dd($data);

ofcourse in your controller,not views~

Sign up to request clarification or add additional context in comments.

4 Comments

I see, can you explain what a controller is and how you go about with them, I am trying to figure out how to work with this framework. :S
In this case you will need to get at least basics as Controllers, Models, Views etc: laravel.com/docs/5.3. Here is another tutorialspoint.com/laravel
I've made the model that should read from my table. But i am still getting errors when i try to USE my model: Fatal error: Class 'App\Booking' not found in C:\xampp\htdocs\resources\views\welcome.blade.php on line 10
@ThimoFranken just check links which I've posted above. They will help you a lot how to start.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.