Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Trev21's avatar

PHP CODE IN LARAVEL

Is it possible to use php code in laravel? I find laravel very secure than plain php itself but the ADD, DELETE, UPDATE using multiple tables in laravel is kinda complicated, using plain PHP inside the laravel view would be my idea, is it possible?

0 likes
5 replies
Trev21's avatar

same thing would apply to adding right inside laravel view? sorry im not proficient in laravel

@php
    INSERT INTO table_name (column1, column2, column3,...) etc.... 
@endphp
xmarks's avatar

You should avoid any queries inside your View.

These should be done in the Controller and/or Model Level. From your View you should simply pass a request to the Controller, and it would give you a response back into your View.

mushood's avatar

It would be possible. BUT in the laravel view, aka blade file, you would only want to "echo" variables to your user.

If you want to perform database queries, you should do so in the controller.

While eloquent provides a good abstraction layer, you can still use RAW sql. Check out documentation here: https://laravel.com/docs/5.5/queries#raw-expressions

If you are really new to laravel, I would suggest going through the laravel from scratch series on this site ;)

Please or to participate in this conversation.