Treeview with --- select option - html

I'm building a treeview inside my Laravel application but I have a problem with the view. I'm currently getting everything under the same select box, for example:
demo1
demo2
demo3
However, I want this inside select options like:
demo1
--- demo2
------ demo3
Controller:
$categories = Pool::where('parent_id', '=', 0)->get();
$allCategories = Pool::pluck('title','id')->all();
return view('admin.accept', compact(['categories','allCategories']));
View:
<div class="form-group {{ $errors->has('parent_id') ? 'has-error' : '' }}">
{!! Form::label('Pool:') !!}
{!! Form::select('parent_id',$allCategories, old('parent_id'), ['class'=>'form-control', 'placeholder'=>'Kies uw Pool']) !!}
<span class="text-danger">{{ $errors->first('parent_id') }}</span>
</div>
<div class="form-group {{ $errors->has('title') ? 'has-error' : '' }}">
{!! Form::label('Naam:') !!}
{!! Form::text('title', old('title'), ['class'=>'form-control', 'placeholder'=>'Enter Title']) !!}
<span class="text-danger">{{ $errors->first('title') }}</span>
</div>
How can I do this?
How can I build a treeview inside my Laravel application?

Related

Pass data from class select to get route

how can I pass data from this form to my route?
<div class="panel-body">
{!! Form::open(array('route'=>'show.exclusion')) !!}
<div class="form-group">
{{Form::label('choosegroup', 'Wähle eine Gruppe')}}
<select class="form-control m-bot15" name="idgroup">
#foreach($groups as $group)
<option value="{{ $group->id }}">{{ $group->name }}</option>
#endforeach
</select>
{{ csrf_field() }}
</div>
<div>
{{Form::submit('Search',['class' => 'btn btn-primary'])}}
<a class="btn btn-default btn-close" href="{{ route('home') }}">Cancel</a>
</div>
{!! Form::close() !!}
</div>
This is my route...
Route::get('exclusion/show/{id}', 'ExclusionController#show')->name('show.exclusion');
First I put the $group->id parameter into the array route part. But I cannot use them at this point of my code.
Any Ideas?
EDIT:
public function show($id)
{
$member = Nerd::find($id);
return view('groups.test')->with('member', $member);
}
You need to pass the whole Request to the function. Than it is possible to get the Values of your Formdata.
public function update(Request $request, $id)
{
$idgroup = $request->input('idgroup');
}
For more details have a look here:
https://laravel.com/docs/5.6/requests
You can use request() method to fetch form data without any class dependencies.
For example:
request()->id;

Radio Button Pass The Wrong Value

I have a radio button form with only two values, admin and operator.
Here is the blade
{{-- Level --}}
#if ($errors->any())
<div class="grouped fields {{ $errors->has('level') ? 'input error' : 'success' }}">
#else
<div class="grouped fields">
#endif
{{ Form::label('level', 'LEVEL:') }}
<div class="field">
<div class="ui radio checkbox">
{{ Form::radio('level', 'admin') }}
<label>Administrator</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
{{ Form::radio('level', 'operator') }}
<label>Operator</label>
</div>
</div>
#if ($errors->has('level'))
<div class="ui pointing red basic label">
{{ $errors->first('level') }}
</div>
#endif
</div>
store controller
public function store(Request $request)
{
$data = $request->all();
$validasi = Validator::make($data, [
'name' => 'required|max:200',
'email' => 'required|email|max:100|unique:users',
'password' => 'required|confirmed|min:6',
'level' => 'required|in:admin,operator',
]);
if ($validasi->fails()) {
return redirect('dashboards/users/create')
->withInput()
->withErrors($validasi);
}
// hash pass
$data['password'] = bcrypt($data['password']);
User::create($data);
Session::flash('flash_message', 'Data user berhasil disimpan');
return redirect('dashboards/users/index');
}
I'm not sure whats wrong with the blade or maybe controller. no matter what i choose, the radio button only pass the admin to the database
any clue?

QueryException (23000) SQLSTATE[23000]: Integrity constraint v1452

I am sucked by this error since this week could any one help me please !
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (practice2.posts, CONSTRAINT posts_category_id_foreign FOREIGN KEY (category_id) REFERENCES categories (id)) (SQL: insert into posts (author_id, updated_at, created_at) values (2, 2017-11-13 05:48:53, 2017-11-13 05:48:53))
my codes are:
Blog controller :
public function store(Requests\PostRequest $request)
{
$request->user()->posts()->create($request->all());
redirect('/backend/blog')->with('message', 'Your post was created successfully!');
}
**migration:**
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('author_id')->unsigned();
$table->foreign('author_id')->references('id')->on('users')->onDelete('restrict');
$table->string('tittle');
$table->string('slug')->unique;
$table->text('excerpt');
$table->text('body');
$table->string('image')-> nullable();
$table->timestamps();
});
}
alter_post_migration :
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->integer('category_id')->unsigned();
$table->foreign('category_id')->references('id')->on('categories')->onDelete('restrict');
//
});
}
create post form:
<div class="box-body ">
{!! Form::model($post, [
'method' => 'POST',
'route' => 'back.store'
]) !!}
<div class="form-group {{ $errors->has('tittle') ? 'has-error' : '' }}">
{!! Form::label('tittle') !!}
{!! Form::text('tittle', null, ['class' => 'form-control']) !!}
#if($errors->has('tittle'))
<span class="help-block">{{ $errors->first('tittle') }}</span>
#endif
</div>
<div class="form-group {{ $errors->has('slug') ? 'has-error' : '' }}">
{!! Form::label('slug') !!}
{!! Form::text('slug', null, ['class' => 'form-control']) !!}
#if($errors->has('slug'))
<span class="help-block">{{ $errors->first('slug') }}</span>
#endif
</div>
<div class="form-group">
{!! Form::label('excerpt') !!}
{!! Form::textarea('excerpt', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group {{ $errors->has('body') ? 'has-error' : '' }}">
{!! Form::label('body') !!}
{!! Form::textarea('body', null, ['class' => 'form-control']) !!}
#if($errors->has('body'))
<span class="help-block">{{ $errors->first('body') }}</span>
#endif
</div>
<div class="form-group {{ $errors->has('published_at') ? 'has-error' : '' }}">
{!! Form::label('published_at', 'Publish Date') !!}
{!! Form::text('published_at', null, ['class' => 'form-control', 'placeholder' => 'Y-m-d H:i:s']) !!}
#if($errors->has('published_at'))
<span class="help-block">{{ $errors->first('published_at') }}</span>
#endif
</div>
<div class="form-group {{ $errors->has('category_id') ? 'has-error' : '' }}">
{!! Form::label('category_id', 'Category') !!}
{!! Form::select('category_id', App\Category::pluck('tittle', 'id'), null, ['class' => 'form-control', 'placeholder' => 'Choose category']) !!}
#if($errors->has('category_id'))
<span class="help-block">{{ $errors->first('category_id') }}</span>
#endif
</div>
<hr>
{!! Form::submit('Create new post', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
</div>
The error:
Integrity constraint violation: 1452 Cannot add or update a child row:
a foreign key constraint fails (practice2.posts, CONSTRAINT
posts_category_id_foreign FOREIGN KEY (category_id) REFERENCES
categories (id))
comes when two table share a relationship of foreign key and you are trying to add some data in child table and its associated record does not exist in the parent table. So check the data accordingly and try again.

How to define hyperlink in Laravel Blade template?

There is a button,which will redirect to a new page after being clicked.
I want to define a hyperlink for this in laravel blade template.
{!! Form::button('<span class="fa fa-arrow-circle-right"></span> Start',
array('class' => 'btn btn-next next-step pull-right'))
!!}
Wrap your button with a form:
<form action="http://example.com">
// button code
</form>
Or:
{!! Form::open(['url' => 'http://example.com']) !!}
// button code
{!! Form::close() !!}
{!! Form::open(['route' => 'route.name']) !!}
// button code
{!! Form::close() !!}
{!! Form::open(['action' => 'Controller#action']) !!}
// button code
{!! Form::close() !!}

LARAVEL styled password field with bootstrap

in this form i heve Form::password() and i can not styled or embeded class for that. for example this below class and style for Form::text can work correctly.
{{ Form::text('username', Input::old('username'), array('placeholder'=>'UserName', 'class'=>'form-control' ) ) }}
Generated HTML:
<input id="username" class="form-control" type="text" name="username" placeholder="username">
but for Form::password() do not work:
{{ Form::password('password', null, array('placeholder'=>'Password', 'class'=>'form-control' ) ) }}
Generated HTML:
<input id="password" type="password" value="" name="password">
This will work:
{{ Form::password('password', array('placeholder'=>'Password', 'class'=>'form-control' ) ) }}
You don't need the null as you cannot specify a default value for password fields.
You can also use a custom HTML macro that enables the syntax similar to your first example.
See my answer here:
How to pass value to Password field in Laravel
This problem occurred when the null value in the password.
{!! Form::password('password', old('password'), ['class' => 'form-control ', 'placeholder' => 'Enter Password']) !!}
Please Remove the old('password'):
{!! Form::password('password', ['class' => 'form-control', 'placeholder' => 'Enter Password']) !!}