{"id":3478,"date":"2016-04-29T13:15:24","date_gmt":"2016-04-29T09:15:24","guid":{"rendered":"http:\/\/dhtmlx.com\/blog\/?p=3478"},"modified":"2025-03-28T19:38:14","modified_gmt":"2025-03-28T16:38:14","slug":"javascript-data-grid-with-laravel-5-usage-guide","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/javascript-data-grid-with-laravel-5-usage-guide\/","title":{"rendered":"JavaScript Data Grid with Laravel 5 Usage Guide"},"content":{"rendered":"<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/PHP\" target=\"_blank\">PHP<\/a> is probably one of the most popular programming languages. Especially if we talk about the web development. Following the intention to complexity reduction, dozens of PHP frameworks have been created. One of the most popular among them is <a href=\"https:\/\/laravel.com\/\" target=\"_blank\">Laravel<\/a>. You can check this <a href=\"https:\/\/www.sitepoint.com\/best-php-framework-2015-sitepoint-survey-results\/\" target=\"_blank\">framework popularity survey<\/a> made by sitepoint to make sure that Laravel at least deserves your attention.<\/p>\n<p><strong>Download <a href=\"\/\/dhtmlx.com\/docs\/products\/dhtmlxGrid\/download.shtml\" onclick=\"ga('send', 'event', 'link', 'click', 'download-grid-laravel-link')\">dhtmlxGrid &#8211; JavaScript Data Table<\/a>, or <a href=\"\/\/dhtmlx.com\/docs\/products\/dhtmlxSuite\/download.shtml\" onclick=\"ga('send', 'event', 'link', 'click', 'download-suite-laravel-link')\">the whole JS library with more than 20 components<\/a><\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2016\/04\/js-data-grid-1.png\" alt=\"js data grid\" width=\"600\" height=\"373\" class=\"aligncenter size-full wp-image-3304\" \/><\/p>\n<p align=\"center\"><em>Spoiler! That&#8217;s how dhtmlxGrid will look like in the version 5.0 ;)<\/em><\/p>\n<p>This article&#8217;s aim is to describe the basics of Laravel usage. This framework was created for the development of web applications following the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Model%E2%80%93view%E2%80%93controller\" target=\"_blank\">model\u2013view\u2013controller<\/a> (MVC) architectural pattern. One of the core features of Laravel is a modular packaging system that allows adding new components to your project. Since we&#8217;re not interesting in the creation of a simple &#8220;Hello, World!&#8221; application, we&#8217;ll use this feature to create something that looks like an actual web app. We&#8217;ll use our dhtmlxGrid component for our task. It&#8217;s a <a href=\"\/\/dhtmlx.com\/docs\/products\/dhtmlxGrid\/\">JavaScript grid library<\/a> that you can use for creating Ajax-enabled tables with rich in-cell editing, built-in filtering, searching, and grouping capabilities.<br \/>\n<!--more--><\/p>\n<p>dhtmlxGrid doesn&#8217;t require a big amount of code for using it, and one article will be enough to create a working example. <\/p>\n<h3><b>Step 1. Using Composer to Install Laravel<\/b><\/h3>\n<p><\/p>\n<p><a href=\"https:\/\/getcomposer.org\/\" target=\"_blank\">Composer<\/a> is a package manager for PHP that we can use to create a new Laravel project and install the required dhtmlxGrid files. If you use a Linux distribution, Composer is possibly available through a repository, and you can install it using your package manager like you install any other package. Otherwise, you can follow this <a href=\"https:\/\/getcomposer.org\/download\/\" target=\"_blank\">installation guide<\/a>.<\/p>\n<p>There&#8217;s a well-written <a href=\"https:\/\/laravel.com\/docs\/5.1\/installation\" target=\"_blank\">guide<\/a> that describes in detail how you can install Laravel, create and configure a new project. We&#8217;ll use previously installed Composer.<\/p>\n<p>Run in your terminal:<\/p>\n<div class=\"codecolorer-container text default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">composer create-project &nbsp;laravel\/laravel --prefer-dist dhtmlxGrid<\/div><\/div>\n<p>This command will create a new Laravel project in a directory named <em>dhtmlxGrid<\/em>. If you want, you can check if everything works well. Open the newly created directory and run the server:<\/p>\n<div class=\"codecolorer-container text default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">cd dhtmlxGrid<br \/>\nphp artisan serve<\/div><\/div>\n<p>Now you can open <strong>http:\/\/localhost:8000\/<\/strong> in your browser. Here&#8217;s what you should get:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2016\/04\/laravel-5-with-grid.png\" alt=\"laravel 5 with grid\" width=\"600\" height=\"400\" class=\"aligncenter size-full wp-image-3301\" \/><\/p>\n<p>Everything works which means that we can return to our application. Now we need to install <a href=\"https:\/\/docs.dhtmlx.com\/connector__php__index.html\" target=\"_blank\">dhtmlxConnector<\/a> which enables access to external data sources. We need it for saving and loading the data. The best thing about using Laravel is the possibility to add this component to a project via composer using a single command.<\/p>\n<p>You can use the <a href=\"https:\/\/packagist.org\/\" target=\"_blank\">Packagist<\/a> website if you want to find a proper package. You can find comprehensive information about the component that you want to use. Composer installation command, requirements, short description, link to the documentation page, etc.:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2016\/04\/server-side-connector.png\" alt=\"server side connector\" width=\"600\" height=\"288\" class=\"aligncenter size-full wp-image-3302\" \/><\/p>\n<p>In our case, to install dhtmlxConnector you should use the following command:<\/p>\n<div class=\"codecolorer-container text default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">composer require dhtmlx\/connector-php<\/div><\/div>\n<h3><b>Step 2. Get the dhtmlxGrid Package<\/b><\/h3>\n<p><\/p>\n<p>After the installation complete, we should download the package with <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxGrid\/\">dhtmlxGrid<\/a>. Within the <em>public<\/em> folder of your project create a new directory named <em>dhtmlxGrid<\/em> and unpack the content of the package into it. <\/p>\n<h3><b>Step 3. Create the Database<\/b><\/h3>\n<p><\/p>\n<p>You can <a href=\"https:\/\/dhtmlx.com\/x\/download\/regular\/dhtmlxConnector\/laravel_dhtmlx.zip\" target=\"_blank\">download<\/a> the pre-created zip archive that contains the database dump file we can use. Unpack the archive and you&#8217;ll see the dhtmlx_samples.sql file. <\/p>\n<p>Now, we can create a new database. If you use MySQL run:<\/p>\n<div class=\"codecolorer-container text default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">mysql -u root -p<\/div><\/div>\n<p>After you insert the password, you can create a new database and import the data from the dump file into it:<\/p>\n<div class=\"codecolorer-container text default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">CREATE DATABASE grid;<br \/>\nUSE grid;<br \/>\n&nbsp;\\. \/path\/to\/file\/dhtmlx_samples.sql<\/div><\/div>\n<p>After you finish with this task, we can finally create the application.<\/p>\n<h3><b>Step 4. Create a Model<\/b><\/h3>\n<p><\/p>\n<p>We need to specify the appropriate model class to get the access to the data. Create a new file named <em>Grid.php<\/em> within the <em>app directory of your project:<\/em><\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"kw2\">&lt;?php<\/span><br \/>\n<span class=\"kw2\">namespace<\/span> App<span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">use<\/span> Illuminate\\Database\\Eloquent\\Model<span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"kw2\">class<\/span> Grid <span class=\"kw2\">extends<\/span> Model<br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">protected<\/span> <span class=\"re0\">$table<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;scheduler_events&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">public<\/span> <span class=\"re0\">$primaryKey<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;event_id&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">public<\/span> <span class=\"re0\">$timestamps<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw4\">false<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>That&#8217;s it. Now we can create the View Object.<\/p>\n<h3><b>Step 5. Create the View Object<\/b><\/h3>\n<p><\/p>\n<p>Within the resources\/views directory, create a new file named <em>grid.php<\/em>:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc0\">&lt;!DOCTYPE html&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"kw2\">head<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;dhtmlxGrid\/codebase\/dhtmlxgrid.js&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">link<\/span> <span class=\"kw3\">rel<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;stylesheet&quot;<\/span> <span class=\"kw3\">href<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;dhtmlxGrid\/codebase\/dhtmlxgrid.css&quot;<\/span>&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">head<\/span>&gt;<\/span><br \/>\n<br \/>\n<span class=\"sc2\">&lt;<span class=\"kw2\">body<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;grid_here&quot;<\/span> <span class=\"kw3\">style<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;width: 600px; height: 400px;&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; mygrid = new dhtmlXGridObject('grid_here');<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; mygrid.setHeader(&quot;Start date,End date,Text&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; mygrid.init();<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; mygrid.load(&quot;.\/grid_data&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; var dp = new dataProcessor(&quot;.\/grid_data&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; dp.init(mygrid);<br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">body<\/span>&gt;<\/span><\/div><\/div>\n<h3><b>Step 6. Create the Controller<\/b><\/h3>\n<p><\/p>\n<p>The controller that we want to create will do two things: load the view, and load and process the data.<\/p>\n<p>To load and process data we will use GridConnector:<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"re0\">$connector<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw2\">new<\/span> GridConnector<span class=\"br0\">&#40;<\/span><span class=\"kw4\">null<\/span><span class=\"sy0\">,<\/span> <span class=\"st0\">&quot;PHPLaravel&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$connector<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">configure<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">new<\/span> Grid<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span><span class=\"st0\">&quot;event_id&quot;<\/span><span class=\"sy0\">,<\/span><span class=\"st0\">&quot;start_date,end_date,event_name&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$connector<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">render<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>The GridConnector constructor takes 2 parameters:<\/p>\n<ul>\n<li><strong>null<\/strong> &#8211; null is passed, as a model, not a database is used;<\/li>\n<li><strong>$PHPLaravel<\/strong> &#8211; the module for working with PHP, the hardcoded value;<\/li>\n<\/ul>\n<p><\/p>\n<p>The configure method configures the GridConnector object without rendering data and takes 5 parameters:<\/p>\n<ul>\n<li><strong>new $modelName<\/strong> &#8211; the method creating a model. In this case, new Grid() that we have defined earlier;<\/li>\n<li><strong>$id<\/strong> &#8211; the name of the id field;<\/li>\n<li><strong>$text<\/strong> &#8211; a comma separated list of rendered data fields;<\/li>\n<li><strong>$extra<\/strong> &#8211; (optional) a comma separated list of extra fields;<\/li>\n<li><strong>$relation_id<\/strong> &#8211; (optional) used for building hierarchy in case of Tree and TreeGrid;<\/li>\n<\/ul>\n<p><\/p>\n<p>Now, within the <em>app\/Http\/Controllers<\/em> folder create a new file, <em>GridController.php<\/em>:<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"kw2\">&lt;?php<\/span><br \/>\n<span class=\"kw2\">namespace<\/span> App\\Http\\Controllers<span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">use<\/span> App\\Grid<span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">use<\/span> Dhtmlx\\Connector\\GridConnector<span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"kw2\">class<\/span> GridController <span class=\"kw2\">extends<\/span> Controller<br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">public<\/span> <span class=\"kw2\">function<\/span> data<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$connector<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw2\">new<\/span> GridConnector<span class=\"br0\">&#40;<\/span><span class=\"kw4\">null<\/span><span class=\"sy0\">,<\/span> <span class=\"st0\">&quot;PHPLaravel&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span> &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$connector<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">configure<\/span><span class=\"br0\">&#40;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">new<\/span> Grid<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;event_id&quot;<\/span><span class=\"sy0\">,<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;start_date, end_date, event_name&quot;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$connector<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">render<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<h3><b>Step 7. Final Configuration<\/b><\/h3>\n<p><\/p>\n<p>We should edit the <em>.env<\/em> file that you can find within the root file of your project. We need to change four lines to give Laravel access to the previously created database:<\/p>\n<div class=\"codecolorer-container text default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">DB_HOST=localhost<br \/>\nDB_DATABASE=grid<br \/>\nDB_USERNAME=root<br \/>\nDB_PASSWORD=yourpassword<\/div><\/div>\n<p>Now, let&#8217;s deal with routes. If you open the <em>app\/Http\/routes.php<\/em> file you&#8217;ll find the default route configuration that may look like this:<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\">Route<span class=\"sy0\">::<\/span><span class=\"me2\">get<\/span><span class=\"br0\">&#40;<\/span><span class=\"st_h\">'\/'<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">function<\/span> <span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> view<span class=\"br0\">&#40;<\/span><span class=\"st_h\">'welcome'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>This code will perform the GET request after you open your project in a browser. As a result, the welcome view from the <em>resources\/views<\/em> folder will be returned. We should replace it with the previously created view, <em>grid.php<\/em>. The other step is to use GridController to save and load data. All you need to do is to replace the existing route with the following:<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\">Route<span class=\"sy0\">::<\/span><span class=\"me2\">get<\/span><span class=\"br0\">&#40;<\/span><span class=\"st_h\">'\/'<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">function<\/span> <span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> view<span class=\"br0\">&#40;<\/span><span class=\"st_h\">'grid'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\nRoute<span class=\"sy0\">::<\/span><span class=\"me2\">match<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#91;<\/span><span class=\"st_h\">'get'<\/span><span class=\"sy0\">,<\/span> <span class=\"st_h\">'post'<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy0\">,<\/span> <span class=\"st_h\">'\/grid_data'<\/span><span class=\"sy0\">,<\/span> <span class=\"st0\">&quot;GridController@data&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>One more step left. Laravel protects your application from cross-site request forgeries by generating a CSRF &#8220;token&#8221; for each active user session managed by the application. You can read more about the mechanisms of protection on this page if you want, but what we need to do now is to exclude one particular URI from CSRF protection. The one that triggered when created data is supposed to be saved. We need to add a proper value to the $except property in the file <em>app\/Http\/Middleware\/VerifyCsrfToken.php<\/em>:<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"kw2\">protected<\/span> <span class=\"re0\">$except<\/span> <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"st_h\">'grid_data'<\/span><br \/>\n<span class=\"br0\">&#93;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<h3><b>Step 8. Run the Application<\/b><\/h3>\n<p><\/p>\n<p>Open your project&#8217;s directory and run in terminal:<\/p>\n<div class=\"codecolorer-container text default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">php artisan serve<\/div><\/div>\n<p>Open http:\/\/localhost:8000\/ in your browser and you\u2019ll see the working dhtmlxGrid:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2016\/04\/laravel-with-datagrid.png\" alt=\"laravel with datagrid\" width=\"600\" height=\"400\" class=\"aligncenter size-full wp-image-3306\" \/><\/p>\n<p>Here&#8217;s the table that contains the data from our database.<\/p>\n<p>That&#8217;s all. We hope you have enjoyed the tutorial.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP is probably one of the most popular programming languages. Especially if we talk about the web development. Following the intention to complexity reduction, dozens of PHP frameworks have &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3803,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,71,1],"tags":[33,6,14,46,49],"class_list":["post-3478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-posts-for-codeproject-com","category-tutorials","category-uncategorized","tag-all-posts","tag-dhtmlxgrid","tag-tips","tag-laravel","tag-php"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/3478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=3478"}],"version-history":[{"count":3,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/3478\/revisions"}],"predecessor-version":[{"id":13632,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/3478\/revisions\/13632"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/3803"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=3478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=3478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=3478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}