Learn from your fellow PHP developers with our PHP blogs, or help share the knowledge you've gained by writing your own.
composer global require "laravel/installer"
and then Laravel new
or composer create-project --prefer-dist laravel/laravel
or git clone https://github.com/laravel/laravel/tree/master
and after that composer updatePHP artisan serve
php artisan serve --port
composer require consoletvs/charts
config/app.php
'providers' => [
....
ConsoleTVs\Charts\ChartsServiceProvider::class,
],
'aliases' => [
....
'Charts' => ConsoleTVs\Charts\Facades\Charts::class,
]
.env
file or config/database.php
file.database/migration
folder.php artisan tinker>>> factory(App\User::class, 20)->create();
the above command will create a set of 20 records. php artisan tinker>>> factory(App\User::class, 2000)->create();
php artisan make controller:<controller_name>
web.php
:Route::get('create-chart/{type}','ChartController@makeChart');
makeChart()
function inside chartcontrollerUse charts;
public function makeChart($type)
{
switch ($type) {
case 'bar':
$users = User::where(DB::raw("(DATE_FORMAT(created_at,'%Y'))"),date('Y'))
->get();
$chart = Charts::database($users, 'bar', 'highcharts')
->title("Monthly new Register Users")
->elementLabel("Total Users")
->dimensions(1000, 500)
->responsive(true)
->groupByMonth(date('Y'), true);
break;
case 'pie':
$chart = Charts::create('pie', 'highcharts')
->title('HDTuto.com Laravel Pie Chart')
->labels(['Codeigniter', 'Laravel', 'PHP'])
->values([5,10,20])
->dimensions(1000,500)
->responsive(true);
break;
case 'donut':
$chart = Charts::create('donut', 'highcharts')
->title('HDTuto.com Laravel Donut Chart')
->labels(['First', 'Second', 'Third'])
->values([5,10,20])
->dimensions(1000,500)
->responsive(true);
break;
case 'line':
$chart = Charts::create('line', 'highcharts')
->title('HDTuto.com Laravel Line Chart')
->elementLabel('HDTuto.com Laravel Line Chart Lable')
->labels(['First', 'Second', 'Third'])
->values([5,10,20])
->dimensions(1000,500)
->responsive(true);
break;
case 'area':
$chart = Charts::create('area', 'highcharts')
->title('HDTuto.com Laravel Area Chart')
->elementLabel('HDTuto.com Laravel Line Chart label')
->labels(['First', 'Second', 'Third'])
->values([5,10,20])
->dimensions(1000,500)
->responsive(true);
break;
case 'geo':
$chart = Charts::create('geo', 'highcharts')
->title('HDTuto.com Laravel GEO Chart')
->elementLabel('HDTuto.com Laravel GEO Chart label')
->labels(['ES', 'FR', 'RU'])
->colors(['#3D3D3D', '#985689'])
->values([5,10,20])
->dimensions(1000,500)
->responsive(true);
break;
default:
break;
}
return view('chart', compact('chart'));
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Charts</title>
{!! Charts::styles() !!}
</head>
<body>
<div class="app">
<center>
{!! $chart->html() !!}
</center>
</div>
{!! Charts::scripts() !!}
{!! $chart->script() !!}
</body>
</html>
php artisan serve
command:http://localhost:8000/create-chart/bar
http://localhost:8000/create-chart/pie
http://localhost:8000/create-chart/donut
http://localhost:8000/create-chart/line
http://localhost:8000/create-chart/area
http://localhost:8000/create-chart/geo
dompdf
package for generating the PDF file. barryvdh/laravel-dompdf
using composer package and thereafter we will add new route url with controller. Then we will create a blade file. Then after we have to just run project with serve and we can check the PDF file is for download. dompdf
. To get started, we need to download fresh Laravel 5.7 application using command, so open our terminal and run the below command in the command prompt: composer create-project --prefer-dist laravel/laravel blog
composer require barryvdh/laravel-dompdf
'providers' => [
....
Barryvdh\DomPDF\ServiceProvider::class,
],
'aliases' => [
....
'PDF' => Barryvdh\DomPDF\Facade::class,
]
Route::get('demo-generate-pdf','HomeController@demoGeneratePDF');
generatePDF()
method of route. <?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PDF;
class HomeController extends Controller
{
public function demoGeneratePDF()
{
$data = ['title' => 'Welcome to My Blog'];
$pdf = PDF::loadView('myPDF', $data);
return $pdf->download('demo.pdf');
}
}
<!DOCTYPE html>
<html>
<head>
<title>Hi</title>
</head>
<body>
<h1>Welcome to My BLOG - {{ $title }}</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</body>
</html>
php artisan serve
$key = ftok(__FILE__, 'A');
$queue = msg_get_queue($key);
msg_send($queue, 1, 'message, type 1');
msg_send($queue, 2, 'message, type 2');
msg_send($queue, 3, 'message, type 3');
msg_send($queue, 1, 'message, type 1');
echo "send 4 messages
";
queue-receive.php$key = ftok('queue-send.php', 'A');
$queue = msg_get_queue($key);
for ($i = 1; $i <= 3; $i++) {
echo "type: {$i}
";
while ( msg_receive($queue, $i, $msgtype, 4096, $message, false, MSG_IPC_NOWAIT) ) {
echo "type: {$i}, msgtype: {$msgtype}, message: {$message}
";
}
}
u% php queue-send.php
send 4 messages
u% php queue-receive.php
type: 1
type: 1, msgtype: 1, message: s:15:"message, type 1";
type: 1, msgtype: 1, message: s:15:"message, type 1";
type: 2
type: 2, msgtype: 2, message: s:15:"message, type 2";
type: 3
type: 3, msgtype: 3, message: s:15:"message, type 3";
while (msg_receive($queue, $i, $msgtype, 4096, $message, false, MSG_IPC_NOWAIT)) {
$key = ftok('queue-send.php', 'A');
$queue = msg_get_queue($key);
while ( msg_receive($queue, 0, $msgtype, 4096, $message) ) {
echo "msgtype: {$msgtype}, message: {$message}
";
}
$pid = pcntl_fork();
$key = ftok('queue-send.php', 'A');
$queue = msg_get_queue($key);
if ($pid == -1) {
exit;
} elseif ($pid) {
exit;
} else {
while ( msg_receive($queue, 0, $msgtype, 4096, $message) ) {
echo "msgtype: {$msgtype}, message: {$message}
";
}
}
posix_setsid();
$id = ftok(__FILE__, 'A');
$shmId = shm_attach($id);
$var = 1;
if (shm_has_var($shmId, $var)) {
$data = (array) shm_get_var($shmId, $var);
} else {
$data = array();
}
$data[time()] = file_get_contents(__FILE__);
shm_put_var($shmId, $var, $data);
$id = ftok(__DIR__ . '/shared-memory-write-base.php', 'A');
$shmId = shm_attach($id);
$var = 1;
if (shm_has_var($shmId, $var)) {
$data = (array) shm_get_var($shmId, $var);
} else {
$data = array();
}
foreach ($data as $key => $value) {
$path = "/tmp/$key.php";
file_put_contents($path, $value);
echo $path . PHP_EOL;
}
$id = ftok(__FILE__, 'A');
$semId = sem_get($id);
sem_acquire($semId);
$data = file_get_contents(__DIR__.'/06050396.JPG', FILE_BINARY);
$shmId = shm_attach($id, strlen($data)+4096);
$var = 1;
if (shm_has_var($shmId, $var)) {
$data = shm_get_var($shmId, $var);
$filename = '/tmp/' . time();
file_put_contents($filename, $data, FILE_BINARY);
shm_remove($shmId);
} else {
shm_put_var($shmId, $var, $data);
}
sem_release($semId);