I am currently new to laravel and I am extremely excited to really begin using it. As I transition by website from a non-framework standard to Laravel, I want to keep track of organization as best as possible.
To my understanding, controllers should serve only one main purpose such that you can run it as:
Route::get("/", "TestController@run"); //example
This controller should only generate data for that specific functionality.
My problem is that on my website I will have two independent scripts that will need to deliver data to my frontend.
Would it be acceptable to join two pieces of data in one controller or is this bad practice? Is there a cleaner way to do this?
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class TestController extends Controller
{
protected $data1 = [];
protected $data2 = [];
public function __construct()
{
$this->middleware('auth');
}
public function run()
{
return view("welcome", array_merge($this->data1, $this->data2));
}
protected function getData1
{
$this->data1 = [somedata..]
}
protected function getData2
{
$this->data2 = [somedata..]
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire