1

I have setup Spark and I have created my custom view in Settings - Students (assume User object is actually a teacher). I have also created migration and model Student.

Now http://spark.app/settings/students returns the page successfully. At this point, I need to return data from backend. I investigated Spark\Http\Controllers\Settings\DashboardController@show - which is the method returning the 'settings' view, however this doesn't return any data to view using ->with('user', $user)

But, as mentioned in Docs, :user="user" :teams="teams" :current-team="currentTeam" already available out of the box.

Where and how does Spark returns these values to /settings? And How do I make my Student object available likewise?


Now, if I want to return my Student object to front-end, I have 2 choices.

1) edit Spark\Http\Controllers\Settings\DashboardController

2) I think Spark\InitialFrontendState is the place where Spark returns these objects user, teams, currentTeam. This approach is something I've seen for the first time to be honest and I didn't really understand how it works.

So how should I achieve in Spark, something as simple as :

return view('spark::settings')->with('student', $student); ?

senty
  • 12,385
  • 28
  • 130
  • 260

1 Answers1

0

Add a new route and set up your own Controller & own view

web.php

Route::get('/settings/students', 'SettingsStudentController@index');

SettingsStudentController.php

class SettingsStudentController extends Controller {
    public function __construct() {
        $this->middleware('auth');
    }
    public function index(Request $request) {
            $user          = Auth::user();
            $student = STUDENTCLASS::whatever();
            return view('yourstudentview', ['student' => $student , 'user' => $user]);
    }
}
timod
  • 585
  • 3
  • 13
  • the question was - how does Spark return these global values – senty Dec 13 '17 at 09:27
  • ahh ok. There is a global spark object (javascript) on every page. set in the vendor\spark\layouts\app.blade.php. it get its variables from the trait ProvidesScriptVariables (vendor\laravel\spark\src\Configuration\ProvidesScriptVariables.php)... a own new Setting page would be much easier because when you update spark to a new version everything gets overwritten – timod Dec 13 '17 at 10:22
  • @senty does it fit for you? – timod Dec 15 '17 at 08:38