1

I'm making web app using Laravel and AngularJS. To prevent CSRF, I added following script to index.php file.

<script>
angular.module("contactApp").constant("CSRF_TOKEN", '<?php echo csrf_token(); ?>');
</script>

But it shows the following Fatal error.

"Call to undefined function csrf_token()"

In Laravel setting, I changed the View Storage Paths in view.php to public_html folder. It seems it makes the error. How I can solve this problem with using an alternative View Storage Paths?

2 Answers 2

1

Probably you have a wrong value in you're view path?

// view.php
'paths' => array(__DIR__.'/../../public'),
Sign up to request clarification or add additional context in comments.

Comments

0

To get a CSRF token in Laravel the code is:

<?php echo Form::token(); ?>

or if your using Blade templates:

{{ Form::token() }}

1 Comment

End-user part is handled by AngularJS and Server part is handled by Laravel, so my challenge is how I can get the CSRF token in AngularJS and send it to Laravel when the end user submit the form. I'm not using the blade templates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.