<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Department;
class DepartmentController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$depart= Department::all()->toArray();
return view('admin.allDepartment', compact('depart'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.adddepartment');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$s = new Department();
$s->departmentname = $request->departmentname;
$s->depstartdate = $request->depstartdate;
$s->save();
return redirect("department");
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$editdepart= department::find($id);
return view ('admin.editDepartment', compact('editdepart'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
and this is migrate table code
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddDepartmentToTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('department', function (Blueprint $table) {
$table->increments('id');
$table->string('departmentname')->unique();
$table->string('depstartdate');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('department', function (Blueprint $table) {
});
}
}
Which view is this? And what is wrapped around it? I suppose you are using a foreach to loop over multiple rows?
Figuring this out should be part of PHP 101 and you should be able to figure this out with basic debugging logic:
Ok, you have an error that says '$row' is not an object. You should ask yourself: Why is this not an object and if it is not an object what is it? An array? A String?
How can you figure that out? Simplest way is to just print the variable $row like: dd($row) or var_export($row). I guess you will see a string or an array in this case.
The question now is, why do you see that value? Probably because the variable in your foreach is not correct. It should be an array of objects or an collection of objects. If it is something else you will get an error like the one you see.