Hallo,
ich bastel gerade an einem Controller rum
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
ab und lasse mir die Tabelle per Ajax senden, bekomme ich einen Fehler 500
Trage ich in der getEdu
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' => $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);
}
}
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());
message: "Trying to get property 'id' of non-object"