public function authorize()
{
return false;
}
You are returning false, which forbids access to everybody. You should change that to return true;
to allow everybody to submit a form.
Of course. I forgot this. Thank you very much. I also forgot to add use Redirect; to PageController.
But now I have error
InvalidArgumentException in UrlGenerator.php line 278:
Route [contacts] not defined.
Np. :)
The new issue is because the route()
method is for named routes. The to()
method is for a specific URI. In your routes file, you defined the contacts URI, but you didn't give it a "name". You only specified the uri and action.
// uri // controller action
Route::get('contacts', 'PageController@contacts');
Changing it like this assigned a "name" to your route.
// uri // route name // controller action
Route::get('contacts', ['as' => 'contacts', 'uses' => PageController@contacts']);
You can read more about that in the docs: http://laravel.com/docs/master/routing
Another option you can do is change the route()
method to the to()
method.
return Redirect::to('contacts')->withCategory($category)
->with('message', 'Thanks for contacting us!');
I want to use input information in $message variable like this
$message->from($request->input('email'), $request->input('name') );
or
$message->from($request->get('email'), $request->get('name') );
but have
ErrorException in PageController.php line 46:
Undefined variable: request
for me it is not obvious why inside one function $request->get('name') works in Array and then doesn't work in $message
public function sendmail(ContactFormRequest $request)
{
$category = Category::where('sef', '=', 'contacts')->first();
Mail::send('emails.contacts',
array(
'name' => $request->get('name'),
'email' => $request->get('email'),
'user_message' => $request->get('message')
),
function($message)
{
$message->from('[email protected]', $request->get('name') );
$message->to('[email protected]', 'Admin');
$message->subject('Письмо с сайта - страница контактов.');
});
return Redirect::route('contacts')->withCategory($category)
->with('message', 'Thanks for contacting us!');
}
From the PHP site themselves (http://php.net/manual/en/functions.anonymous.php):
Closures may also inherit variables from the parent scope. Any such variables must be passed to the use language construct.
So, try changing
function($message)
to
function($message) use ($request)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community