PHP code example of michaeljennings / carpenter

1. Go to this page and download the library: Download michaeljennings/carpenter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

michaeljennings / carpenter example snippets


Carpenter::get('foo');

public function __construct(Michaeljennings\Carpenter\Contracts\Carpenter $carpenter)
{
    $this->carpenter = $carpenter;
}

Carpenter::get('foo');

public function __construct(Michaeljennings\Carpenter\Contracts\Carpenter $carpenter)
{
    $this->carpenter = $carpenter;
}

$carpenter->add('foo', function($table) {});

$table = $carpenter->get('foo');

$table = $carpenter->get('foo');

$table->column('bar');

$table = $carpenter->get('foo', function($table) {
	$table->column('bar');
});


$table = $carpenter->make('foo', function($table) {});

$carpenter->add('foo', function($table) {
	// Table logic goes here.
});

$carpenter->add('bar', Bar::class);

use Michaeljennings\Carpenter\Contracts\Table;

class Bar 
{
	public function build(Table $table)
	{
		//
	}
}

$carpenter->add('bar', "Bar@table");

class Bar
{
	public function table(Table $table)
	{
		//
	}
}

$table->model(FooModel::class);

$table->data($data);

$table->paginate(15);

$table->column('foo');

$table->column('foo')->sortable();
$table->column('foo')->unsortable();

$table->column('foo')->sort(function($query, $desc) {
	if ($desc) {
	 	$query->orderBy('bar', 'desc');
	} else {
		$query->orderBy('bar', 'asc');
	}
});

$table->column('foo'); // Label: Foo
$table->column('foo_bar'); // Label: Foo Bar
$table->column('foo_bar')->setLabel('Baz') // Label: Baz

$table->column('price')->presenter(function($value) {
	return '&' . number_format($value, 2);
});

$table->column('price')->presenter(function($value, $row) {
	if ($row->online) {
		return '&' . number_format($value, 2);
	}
});

$table->action('create');
$table->action('edit', 'row');

$table->action('create')->setTag('div');

$table->setFormAction('/search');
$table->setFormMethod('GET');

$table->action('create')->setHref('/create');

$table->action('edit', 'row')->setHref(function($id) {
	return '/edit/' . $id;
});

$table->action('edit', 'row')->setHref(function($id, $row) {
	return '/edit/' . $row->slug;
});

$table->action('edit', 'row')->setLabel('Edit');

$table->action('edit', 'row')->setClass('btn');

$table->action('edit', 'row')->id('edit-item');
$table->action('edit', 'row')->setAttribute('id', 'edit-item');

$table->action('edit', 'row')->setAttribute('data-id', function($id, $row) {
	return $id;
});

$table->action('delete', 'table')->confirmed('Are you use you to delete that?');
$table->action('delete', 'row')->confirmed(function($id, $row) {
	return "Are you sure you want to delete {$row->name}?";
});

$table->setTitle('FooBar Table');

$table->filter(function($q) {
	$q->orderBy('foo');
});

$table->get('foo')->filter(function($q) {
	$q->where('foo', '=', 'bar');
});

$table->render();

$table->setTemplate('path/to/template.php');

$table->render('path/to/template.php');
$table->render('path/to/template.php', ['foo' => 'bar']);
$table->render(null, ['foo' => 'bar']);

foreach ($table->getColumns() as $column) {
	//
}

$table->getAttributes();

$table->getLabel();

$table->isSortable();

$table->getHref();

foreach ($table->getRows() as $row) {
	//
}

if ($table->hasRows()) {
	//
}

foreach ($row->getCells() as $cell) {
	echo $cell->value;
}

if ($row->hasActions()) {
	//
}

foreach ($row->getActions() as $action) {
	echo $action->render();
}

if ($table->hasActions()) {
	//
}

foreach ($table->getActions() as $action) {
	echo $action->render();
}

if ($table->hasLinks()) {
	//
}

echo $table->getLinks();

$table->getTitle();

$table->getFormAction();

$table->getFormMethod();