Sunday, May 21, 2017

Laravel method 'table' not found in \Illuminate\..\DB and error: Call to undefined method Illuminate\Database\Query\Builder::table()

i'm trying to get the donors from the database whose email will match the email the user enters. But, i'm getting the error written on the title.I have seen similar questions posted but have found no working answers. My controller has these:

use App\Donor;
use App\Video;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Mail;

The function is as

public function getUserReceipts(Request $data){
        $email = $data->email;

       // $donor = Donor::where('email',$email)->get(); 

the above line was the code i used at first, but it only gave the latest user with that email instead of all users with that email. Then I used the rewrote is as in the line below only to get the same result

         $donor = DB::table('donor')->where('email','=',$email)->get();

         foreach ($donor as $value){
            $first_name = $value->first_name;
            $last_name = $value->last_name;
            $amount_donated = $value->amount_donated;

            echo 'The receipt for '. $first_name . ' '. $last_name. ' is below:'. '<br><br>';


            return view('emails.receipt',compact
            (['first_name','last_name','amount_donated']));

        }

In short, I want to receive the all the data for the particular email entered by the user, but i'm getting the only 1 (the latest data) for that particular email. It seems it is because of:

Method 'table' not found in \Illuminate\Support\Facades\DB If I try to use the previous code( $donor = Donor::where('email',$email)->get(); ), similar thing shows up in the code: Method 'where' not found in \App\Donor

it seems figuring it out would solve this case. Would really appreciate your help. Thanks



via AJth

Advertisement