samedi 7 juillet 2018

(2/2) ErrorException Undefined property: stdClass::$Start (View: /opt/lampp/htdocs/ToDo/resources/views/index.blade.php)

I ran into an error while fetching data from my goals table. Im trying to display all the tables data using foreach loop. But I can't due unkown property error . I'm still learning laravel so kindly help. Here's my controller code.

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use App\goal;
use DB;

class GoalController extends Controller
{
    public function postAddGoal(Request $request){
     $this->validate($request, 
     ['goal'=>'required','checklist'=>'required']);
     $goal_name=$request['goal'];
     $checklist=$request['checklist'];


  $goal = new goal();
     $goal->goal=$goal_name;
     $goal->checklist=$checklist;
     $goal->status='PENDING';
     $goal->start='1002-1-1';
     $goal->finish='1002-1-1';
     $goal->remarks="NULL";
     $goal->score="0";
     $goal->save();

     redirect()->route('seegoals');
    }
    public function getGoals(){


        $goals = DB::select(' select * from goals ');
        if(empty($goals)){
            $goals=0;
        }
        return view('/index', ['goals'=>$goals] );
    }
}

Then my index.blade.php code

@foreach($goals as $goal)
<tr>

    <th colspan="3"></th>
    <th colspan="7"></th>
    <th colspan="2"></th>
    <th colspan="2"></th>
    <th colspan="2"></th>
    <th colspan="2"></th>
    <th colspan="7"></th>

</tr>
@endforeach

I get an exception:

(2/2) ErrorException Undefined property: stdClass::$Start (View: /opt/lampp/htdocs/ToDo/resources/views/index.blade.php) What could be the problem with my code?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire