Ankündigung

Einklappen
Keine Ankündigung bisher.

im Controller Funktioniert Auth::id() nicht

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Laravel] im Controller Funktioniert Auth::id() nicht

    Hallo,

    ich bastel gerade an einem Controller rum

    PHP-Code:
    <?php

    namespace App\Http\Controllers;

    use 
    App\education;
    use 
    Illuminate\Http\Request;
    use 
    Illuminate\Support\Facades\DB;
    use 
    DataTables;
    use 
    App\User;
    use 
    Auth;

    class 
    EducationController extends Controller
    {


        
    /**
         * Display a listing of the resource.
         *
         * @return \Illuminate\Http\Response
         */
        
    public function index()
        {

          
    $ownUser User::find(Auth::id()); //finde UserDaten
          
    $ownEdu $ownUser->education->all(); // finde alle Ausbildungen am User


          
    $allEdu Education::all();

          
    $getEdu = ['eduDaten' =&gt$ownEdu 'allEdu' =>$allEdu];
          return 
    view ('users.education')->with($getEdu); // alle Daten übergeben an den View.
        
    }

        public function 
    getData()
        {
            return 
    Datatables::of(Education::all());
        }

        public function 
    getEduTable(){

            
    $ownUser User::find(1); //finde UserDaten
            
    $ownEdu $ownUser->education->all(); // finde alle Ausbildungen am User

                
    $stringAusbildung "";
                
    $stringAusbildung .= '<table class="table tableMeineVereine">';
                  
    $stringAusbildung .= '<thead class="thead-dark">';
                    
    $stringAusbildung .= '<tr>';
                      
    $stringAusbildung .= '<th scope="col">Ausbildung</th>';
                      
    $stringAusbildung .= '<th scope="col">Ausbildung</th>';
                      
    $stringAusbildung .= '<th scope="col">Action</th>';
                    
    $stringAusbildung .= '</tr>';
                
    $stringAusbildung .= '</thead>';
                
    $stringAusbildung .= '<tbody>';



                foreach(
    $ownEdu as $Edu){

                
    $stringAusbildung .='<tr>';
                  
    $stringAusbildung .='<td>'.$Edu->kurzbez.'</td>';
                  
    $stringAusbildung .='<td>'.$Edu->Langbez.'</td>';
                  
    $stringAusbildung .='<td><button type="button" id="btnAusbildungDel" value="'.$Edu->id.'" class="btn btn-danger btnAusbildungDel">löschen</button></td>';
                
    $stringAusbildung .='</tr>';
                  };


              
    $stringAusbildung .='</tbody>';
              
    $stringAusbildung .='</table>';


              return 
    response()->json($stringAusbildung);


        }




    ich habe ihn mal auf das wesentliche beschnitten.

    in der Index Methode ruft er mir ein Array ab welches ich an den View gebe da gibt es keine Probleme!

    Rufe ich aber die getEduTable mit der
    PHP-Code:
    $ownUser User::find(Auth::id()); 
    ab und lasse mir die Tabelle per Ajax senden, bekomme ich einen Fehler 500
    message: "Trying to get property 'id' of non-object"
    Trage ich in der getEdu
Lädt...
X