Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i use include file with laravel?

I am using Laravel and i found a chart lib for my project. This library(libchart) is php and it use this:

include "../libchart/classes/libchart.php";

but if i put this code in my view, i get this error:

include(../libchart/classes/libchart.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

I dont know how i have to add code in the view or add the library in Laravel.

When i download the library, I have this:

libchart
->libchart
->demo

Then i paste in:

myproject
->app
  ->views
    ->libchart
      ->libchart
      ->demo

And include "../libchart/classes/libchart.php"; is:

libchart
->libchart
->demo
  ->LineChartTest.php

EDIT:

I tried this:

  1. I create a directory called grafico in app.
  2. I did this:

    Route::get('pruebaimagen', function() { include_once(app_path() . '/grafico/libchart/classes/libchart.php'); $data['libchart'] = new Libchart(); return View::make('template', $data); });

In return View::make('template', $data); which type of template i have to use? and i get this error now:

Class 'Libchart' not found
like image 526
Sunday Avatar asked Mar 04 '14 20:03

Sunday


People also ask

What is @include in Laravel?

@include is just like a basic PHP include, it includes a "partial" view into your view. @extends lets you "extend" a template, which defines its own sections etc. A template that you can extend will define its own sections using @yield , which you can then put your own stuff into in your view file.


2 Answers

Forget complex code of core PHP in larval because Laravel has provided a function that uses for add many files in your for blade template code,

@include('foldername.filename')

@include('filename')

They are pure Laravel functions.

like image 161
hemant kumawat Avatar answered Sep 30 '22 18:09

hemant kumawat


Finally i did it. Rahil Wazir helped me, and now my project is working.

My route:

Route::get('pruebaimagen', function() {
    include_once(app_path() . '/librerias/libchart/classes/libchart.php');
    return View::make('demo.LineChartTest');
});

Mi view:

<?php
/* Libchart - PHP chart library
 * Copyright (C) 2005-2011 Jean-Marc Trémeaux (jm.tremeaux at gmail.com)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

/**
 * Line chart demonstration
 *
 */

$chart = new LineChart();

$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("06-01", 273));
$dataSet->addPoint(new Point("06-02", 421));
$dataSet->addPoint(new Point("06-03", 642));
$dataSet->addPoint(new Point("06-04", 799));
$dataSet->addPoint(new Point("06-05", 1009));
$dataSet->addPoint(new Point("06-06", 1406));
$dataSet->addPoint(new Point("06-07", 1820));
$dataSet->addPoint(new Point("06-08", 2511));
$dataSet->addPoint(new Point("06-09", 2832));
$dataSet->addPoint(new Point("06-10", 3550));
$dataSet->addPoint(new Point("06-11", 4143));
$dataSet->addPoint(new Point("06-12", 4715));
$chart->setDataSet($dataSet);

$chart->setTitle("Sales for 2006");
$chart->render("recursos/demo5.png");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Libchart line demonstration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />
</head>
<body>
    <img alt="Line chart" src="generated/demo5.png" style="border: 1px solid gray;"/>
</body>
</html>

I added a folder named "librerias" in app and i pasted the library. Next, I went to:

myproject
->composer.json

I added this: "app/librerias" in

autoload
->classmap

Then i runned with cmd: composer dump-autoload and it worked.

like image 25
Sunday Avatar answered Sep 30 '22 18:09

Sunday