Allow public access to a CRUD create method #598
-
I have a requirement where I'd like to create a form to appear on the public facing (no logged in users) side of my site. Has anyone tried this before? I would like to:
Is this possible? I haven't upgraded to version 6 yet - still on the previous version. Imagine creating an enquiry form but controlling the fields within backpack. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I would suggest that you start from this article: https://backpackforlaravel.com/articles/tutorials/how-to-create-a-custom-operation-that-uses-backpack-fields, but I think it will take much more efforts, as you would have to render the fields in a non-admin UI. |
Beta Was this translation helpful? Give feedback.
-
Hi @sammyblackbaron in my opinion, it would be easier if you create your own CRUD manual like the old way when you're not using backpack instead of using backpack CRUD in the "public" section, because, it will take much pain to modify something. "Use the backpack crud form generator code to create my form (for consistency)" @extends(backpack_view('blank'))
@php
$defaultBreadcrumbs = [
trans('backpack::crud.admin') => url(config('backpack.base.route_prefix'), 'dashboard'),
$crud->entity_name_plural => url($crud->route),
trans('backpack::crud.add') => false,
];
// if breadcrumbs aren't defined in the CrudController, use the default breadcrumbs
$breadcrumbs = $breadcrumbs ?? $defaultBreadcrumbs;
@endphp
@section('header')
<section class="header-operation container-fluid animated fadeIn d-flex mb-2 align-items-baseline d-print-none" bp-section="page-header">
<h1 class="text-capitalize mb-0" bp-section="page-heading">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</h1>
<p class="ms-2 ml-2 mb-0" bp-section="page-subheading">{!! $crud->getSubheading() ?? trans('backpack::crud.add').' '.$crud->entity_name !!}.</p>
@if ($crud->hasAccess('list'))
<p class="mb-0 ms-2 ml-2" bp-section="page-subheading-back-button">
<small>
<a href="{{ url($crud->route) }}" class="d-print-none font-sm">
<span><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></span>
</a>
</small>
</p>
@endif
</section>
@endsection
@section('content')
<div class="row" bp-section="crud-operation-create">
<div class="{{ $crud->getCreateContentClass() }}">
{{-- Default box --}}
@include('crud::inc.grouped_errors')
<form method="post"
action="{{ url($crud->route) }}"
@if ($crud->hasUploadFields('create'))
enctype="multipart/form-data"
@endif
>
{!! csrf_field() !!}
{{-- load the view from the application if it exists, otherwise load the one in the package --}}
@if(view()->exists('vendor.backpack.crud.form_content'))
@include('vendor.backpack.crud.form_content', [ 'fields' => $crud->fields(), 'action' => 'create' ])
@else
@include('crud::form_content', [ 'fields' => $crud->fields(), 'action' => 'create' ])
@endif
{{-- This makes sure that all field assets are loaded. --}}
<div class="d-none" id="parentLoadedAssets">{{ json_encode(Basset::loaded()) }}</div>
@include('crud::inc.form_save_buttons')
</form>
</div>
</div>
@endsection same as like the list.blade.php, etc Okay, so, I already tried what you want to achieve, and what I found is we need to create our custom theme, since it's not authenticated user, I also ever facing the same issue as you, but I won't continue to do it, because it's easier when I create old way CRUD manually instead use from backpack, because I need to overwrite much stuff. That's what I think, if you found me wrong, let's discuss it, thank you. Cheers. |
Beta Was this translation helpful? Give feedback.
Yup, this is what we've done on the Backpack website too. Now in Backpack v6 it's a lot easier than following this tutorial (the whole operation can be created in one line from the command line).
A new form operation gives you the power to do whatever you want. The only "tricky bit" is to make it work for you:
But they're not difficult at all if you ask me.
--
Of course, depending how easy to find this form is... one problem you might run into @sammyblackbaron is SPAM. So I heavily recommend either