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

meeshka's avatar

Using Laravel components in a custom php project

Hi,

I've a custom php project that's old. Although it runs fine with PHP 5.5 it has no input sanitization in place. Is there a way I can make use of Laravel Components within this custom project? That way I can make sure input variables are ($_POST, $_GET...) are sanitized. Any insights?

0 likes
4 replies
tkjaergaard's avatar

All Laravel components are available from here https://github.com/illuminate.

All components are installable throught Composer, but none of them are very well documentent unfornunally.

Laravel does use many Symfony components which are actually very well documented.

But i would imagine that you're interested in the Illuminate\Http component and specifically the Illuminate\Http\Request class, which is just an extension of the Symfony\Component\HttpFoundation\Request with some sugar added to it.

But Neither the Illuminate\Http\Request or the Symfony\Component\HttpFoundation\Request class does any sanitizing.

But if you want to, you could use the Illuminate\Http\Request class and extends it's input method and add sanitization to the value before it's returned?

The Illuminate\Http\Request class is quite simple to bootstrap in you application:

$request = Illuminate\Http\Request::capture();

from here on, you can use the $request->input($key) method to recive a post- or query value.

Hope that pointed you in some direction :)

1 like
phildawson's avatar

^ from that illuminate group the validation component. Here's a quick example inc using the Container

composer require illuminate/validation
<?php require_once '../vendor/autoload.php';

use Illuminate\Container\Container;
use Illuminate\Validation\Factory as ValidatorFactory;
use Symfony\Component\Translation\Translator;

$app = new Container;
$app->singleton('translator', function(){
    return new Translator('en');
});
$app->singleton('validator', function($app){
    return new ValidatorFactory($app['translator']);
});

$validatorFactory = $app->make('validator');

$data = ['foo' => 'bar'];

$rules = ['foo' => 'integer'];

$messages = ['integer' => 'The :attribute field must be integer.'];

$validator = $validatorFactory->make($data, $rules, $messages);

if ($validator->fails()) {
    $messages = $validator->messages();

    echo $messages->first('foo'); // The foo field must be integer.
}

Edit: This is almost exactly the example I had in mind.

https://gist.github.com/spekkionu/e9103993138e666f9f63

1 like

Please or to participate in this conversation.