I want to add extra variables onto my return function. How can I do this?
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request;
use Auth;
use App\User;
use App\Address;
use Illuminate\Support\Facades\Hash;
class ProfileController extends Controller
{
public function returnView()
{
return view('profile')->with('csspath',$this->css)->with('jspath',$this->js)->with('firstname',$this->first_name)->with('lastname',$this->last_name)->with('phone',$this->phone)->with('landline',$this->landline)->with('address',$this->address)->with('page_name','profile')->with('addressbook',$this->addressbook);
}
protected function newAddressBook(Request $request)
{
$extra_data = "I want this added onto the returnview function";
return $this->returnView(); // How do I add more? return $this->returnView()->with('extradata',$extra_data); does not work
}
}
to make things simple and for the sake of readability, i would refactor your code like this
public function returnView($data = []){
return view('profile', array_merge([
'csspath' => $this->css,
'lastname' => $this->last_name
...
...
], $data));
}
protected function newAddressBook(Request $request)
{
return $this->returnView([
'extra_data' => 'this is extra data '
]);
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community