Tag

PHP Archives - Custom Web Application Developers in Bromley, London

Laravel ajax calls failing with response code 419

By | Ajax, Laravel, PHP | No Comments

Recently I was working on a Laravel application with some ajax, and I was getting a 419 error after firing an Ajax call to a Laravel controller.

Laravel requires a token to be sent on some types of requests (POST being one of them), this is to prevent Cross site request forgery ( e.g. a form being submitted from somewhere it was intended by the developer to be submitted from ).

In php files its very easy to add this with the function call csrf_field().

But in js files, we need to essentially pull in this you store the token somewhere on the page and use js to pull it in.

you can pop the token in the page somewhere like this:

 

for reference: https://laravel.com/docs/5.5/csrf

 

 

 

 

Laravel how to set a checkbox value to checked based on models value

By | Laravel, PHP | No Comments

In this post I’ll show how to set a Laravel checkbox value to checked based on the value stored on the model.

In this example I’ll be using the Laravel Collective Form checkbox

In the code example above my checkbox is called ‘collected’ the value when checked is ‘yes’ , I wanted to populate my form with the value from the database stored on the model (which is yes or no on the $gas_cert->collected field of the model), the Form::checkbox wants a boolean to decide whether to check the checkbox or not.

I want the form to take either the last input to the collected input or the value in the database (ie if yes check the checkbox).

If I did want to just take into account the model value it could be simplified to this:

 

 

 

Screen Shot of portfolio section

Create a portfolio section on WordPress website using Custom Post Type (CPT)

By | CSS, Freelance, HTML, PHP, Wordpress | No Comments

I’m going to show you how to create a portfolio section on your WordPress website.

For any many companies (such as web design agencies) and freelancers that work with digital media its important to have a portfolio section on your WordPress website.

I’ll show you how todo this using WordPress Custom Post Types, you’ll easily be able to update the portfolio via the WordPress admin interface without having to write extra html or css.

As I’m a WordPress Developer my portfolio section will focus on showcasing WordPress programming and web design. See  the finished version here.

Read More