Last active
December 15, 2019 03:36
-
-
Save zofe/39c5d07620b8f7e9371291194d6d8680 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Admin; | |
use App\Http\Requests; | |
use App\Article; | |
use App\Tag; | |
use App\Category; | |
use Zofe\Rapyd\DataForm\Field\Checkboxgroup; | |
class AdminArticlesController extends AdminController | |
{ | |
public function anyArticle() | |
{ | |
$edit = \DataEdit::source(new Article()); | |
$edit->add('title', 'Title', 'text')->rule('required'); | |
$edit->add('id_cat','Category','select')>rule('required') | |
->option("","")->options(Category::all()->lists('name','id')) | |
->onchange('$.get("/admin/articles/catcheckbox", {id_cat: $("#id_cat").val()} , function (data) { $("#div_tags").html(data) }'); | |
if ($edit->status!='create') | |
{ | |
$edit->add('tags','Tags','Checkboxgroup') | |
->options( | |
Tag::whereHas('categories', function($query) use ($edit){ | |
return $query->where('id','=',$edit->model->id_cat); | |
})->lists('title_tag','id_tag') | |
)->separator('<br>'); | |
} else { | |
$edit->add('tags','Tags','Checkboxgroup')->separator('<br>'); | |
} | |
$form = $edit->getForm(); | |
return $edit->view('admin.articles.article', array('content' => $form)); | |
} | |
public function anyCatcheckbox() | |
{ | |
$id_cat = \Input::get('id_cat'); | |
$checks = new Checkboxgroup('tags', 'Tags'); | |
$checks->status = 'modify'; | |
$checks->options( | |
Tag::whereHas('categories', function($query) use ($id_cat){ | |
return $query->where('id_tag','=',$id_cat); | |
})->lists('title_tag','id_tag'))->separator('<br>');; | |
$checks->build(); | |
return $checks->output; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment