Various errors trying to add an extra function to CRUD - laravel

First, I clearly do not fully understand routing. This problem is not DB related, but management of images in a folder but I used the Resource process to create the crud elements. Maybe this is not the correct approach for file management.
I have the following view (it is not a finished view, just for testing):
#extends('layouts.app')
#section('content')
<!--/*{ { dd(get_defined_vars(), url()->current()) } }*/-->
#if(!Auth::guest())
#if(Auth::user()->admin == 1)
<h3>Manage Gallery</h3>
#else
<h3>Gallery </h3>
#endif
#else
<h3>Gallery (Visitor)</h3>
#endif
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-align-items: center;
align-items: center;
justify-content: space-around;
flex-wrap: wrap;
min-width: 100px;
max-width: 1100px;
}
.flex-item {
display:flex;
align-items: center;
/*height: 100px;
width: 200px;*/
background-color: #f5f8fa;
color: white;
justify-content: space-between;
margin: 3px;
padding: 10px 0 0 10px;
}
.flex-item img{
flex-grow:0;
flex-shrink:0;
}
span {
padding-left: 5px;
}
</style>
#if(count($data['folders'])>0)
<div class="flex-container">
#foreach ($data['folders'] as $folder)
<div class="flex-item">
<form action="{{action('GalleryController#show', $folder)}}" method="get">
<input name="_method" type="hidden" value="show">
<button class="btn btn-lg px-5 btn-primary" style="margin:5px" type="submit" role="button" <img src="assets/folder_image.png" height="30">{{$folder}}</button>
</form>
<!-- --------------------------------------- -->
<!-- Only show crud buttons if administrator -->
<!-- --------------------------------------- -->
#if(!Auth::guest())
#if(Auth::user()->admin == 1)
Delete 1 Picture
<form action="{{action('GalleryController#destroy', $folder)}}" method="post">
{{csrf_field()}}
<input name="_method" type="hidden" value="DELETE">
<button class="btn btn-danger btn-sm" type="submit">Delete entire Folder</button>
</form>
Add piccies
<form action="{{action('GalleryController#add')}}" method="post">
{{csrf_field()}}
<input name="folder" type="hidden" value='{{$folder}}'>
<button class="btn btn-info btn-sm" style="margin:5px" type="submit">Add new pictures</button>
</form>
#endif
#endif
</div>
#endforeach
#if(!Auth::guest())
#if(Auth::user()->admin == 1)
<div class="flex-item" style="width:1500px"> <!-- large width forces flexbox to new row -->
Create
</div>
#endif
#endif
</div>
#else
#if(!Auth::guest())
#if(Auth::user()->admin == 1)
<br><br><br>
Create
#endif
#endif
<p>No Gallery Folders available.</p>
#endif
#endsection
I cannot recall WHY I use a link for 'delete 1 picture' and a form for 'delete entire folder'. I assume I found it in some tutorial and just used it. I want to either delete a specific image (this works fine using the 'edit' component of the Controller) or delete the entire folder (this also works fine using the 'destroy' component of the Controller).
So the next step is to be able to add new folders, or images to a specific folder. Adding a new folder works fine as well using the 'create' component of the Controller.
Then it falls apart trying to add a new image. With the code as shown, I get 2 different errors depending upon whether I click the 'Add Piccies' button or the 'Add new pictures' button.
My route is (and I have tried both get and post):
Route::post('/gallery/add/', 'GalleryController#add');
/* Dynamically create all routes for CRUD for gallery table */
Route::resource('gallery', 'GalleryController');
If I use the 'add piccies' button I get a URL of 'http://hdkumdo.com/lsapp/public/gallery/add?2019_Masters' where ?2019 etc is the folder concerned.
If I use the 'add new picture' button I get the error "Type error: Too few arguments to function App\Http\Controllers\GalleryController::add(), 0 passed and exactly 1 expected'.
If I change the route from post to get, I get the error ' Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message'.
The rendered view looks like this:
View of buttons
Because I have used the basic CRUD elements created by RESOURCE, I added a new function to the controller thinking I can just call it. The code fragment is:
/**
* Show the form for uploading pictures.
*
* #return \Illuminate\Http\Response
*/
public function add($gallery)
{
$folder = $gallery;
$title = 'Add Pictures';
TheUser::get_Role();
$userRole = session('userRole');
Log::info('GalleryController.add called : user Role =>' . $userRole . ' Folder:' . $folder );
$data = array(
'userRole' => $userRole,
);
/*dd($data);*/
return view('gallery.add')->with('title', $title)->with('data', $data);
}
So, any suggestions/advice etc would be most welcome.

See the comments above. It is something to be aware of as it took me several days of head scratching and required a little lateral thinking.

Related

How can I select the option in the dropdown box?, while no options seen in html in cypress

Hi I am new in exploring cypress.
I notice that, there is no select options in my html code. How can I select the option in the dropdown box?
Let's take a look of my html
<div class="row asset_config">
<div class="loader-container">
<div class="loader-content">
<div class="required form-group"><label for="cc_7sgwxb2v9" class="">allocation</label>
<div class="Select css-b62m3t-container"><span id="react-select-3-live-region" class="css-1f43avz-a11yText-A11yText"></span><span aria-live="polite" aria-atomic="false" aria-relevant="additions text" class="css-1f43avz-a11yText-A11yText"></span>
<div class="Select__control css-1s2u09g-control">
<div class="Select__value-container css-319lph-ValueContainer">
<div class="Select__placeholder css-14el2xx-placeholder" id="react-select-3-placeholder">Select allocation</div>
<div class="Select__input-container css-6j8wv5-Input" data-value=""><input class="Select__input" autocapitalize="none" autocomplete="off" autocorrect="off" id="cc_7sgwxb2v9" spellcheck="false" tabindex="0" type="text" aria-autocomplete="list" aria-expanded="false" aria-haspopup="true" role="combobox" value="" style="color: inherit; background: 0px center; opacity: 1; width: 100%; grid-area: 1 / 2 / auto / auto; font: inherit; min-width: 2px; border: 0px; margin: 0px; outline: 0px; padding: 0px;"></div>
</div>
<div class="Select__indicators css-1hb7zxy-IndicatorsContainer">
<div class="Select__indicator Select__dropdown-indicator css-tlfecz-indicatorContainer" aria-hidden="true"><span class="connect-icon connect-icon-caret-down"></span></div>
</div>
</div><input name="allocationType" type="hidden" value="">
</div>
</div>
</div>
</div>
</div>
In fact, I also notice that, cypress studio suggest me code to click the dropdown box:
cy.get(':nth-child(2) > form > .allocation_session > .asset_config > .loader-container > .loader-content > .required > .Select > .Select__control > .Select__value-container > .Select__input-container').click()
I found that not only unreadable is this approach, but also not reliable, because sometimes suggested codes that click on other dropdown doesnt work, if I didnt run the example code above or other suggested code.
Is there any reason behind why suggested code is coupled with other suggested code?
Is there a better way to select the element I want to get?
edit:
picture included
The react-select has the same user-actions as an ordinary HTML select, but you cannot use cy.select() command on it.
The general pattern is
open the dropdown menu by clicking on the "main" control
find the option you want to select within the menu listbox that is injected into the DOM after the above click action
click that option
verify the text of the option is now showing in the placeholder
// open the dropdown menu
cy.contains('label', 'allocation')
.next('.Select')
.click()
// find the option
cy.contains('Balanced Plus')
.click()
// verify option is selected
cy.contains('label', 'allocation')
.next('.Select')
.find('.Select__placeholder')
.should('contain', 'Balanced Plus')

laravel blade - how to hide the display of an html element for specific routes

folks!
I am using Laravel 5.6 with Hyn Laravel-Tenancy Installed.
I have a main menu that is the same for all tenants (subdomains), however, for one or another specific tenant (subdomain), I would like some items to be displayed from that main menu, but for all other tenants, these menu items not visible and also inaccessible, even if called by the url.
On the Blade I used a "#if route::has", but even limited that route to a specific subdomain, this route is available for all other subdomains, so that #if receives as true and ends up displaying the menu item.
I'm not finding a simple solution, could create a helper that identifies the url and if it is from a specific subdomain, would display the item and for the other subdomains would not be displayed, but "I guess" that it should have a native form using Blade along with "routes\web" to achieve this result.
Thanks!!!
use gate and can in laravel
in authserviceprovider create a gate like that:
$gate->define('see-menu',function(){
//check domains or rules or every thing that you need to check to obtain access
//return true if user have access and false if not access
});
and in you view use can to check see-menu
#can('see-menu')
//your code
<li class="devider"></li>.......
#endcan
u can do it like that i have my routs "admin department listOfTeachers" that thet user can see the button of sidemenu and use it
#if(Request::is('admin') || Request::is('department') || Request::is('listOfTeachers'))
<div id="mySidenav" class="sidenav">
×
<p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">الرئيسية</p>
<p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">قائمة المترشحين</p>
<p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">قائمة الاساتذة</p>
<p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">الشعب و التخصصات</p>
<p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">حسابات العمال</p>
</div>
<div class="centerVertical" style="float:right;margin-right:1.2rem;" onclick="openNav()">
<img src="../resources/images/menu.png" style="margin-top:3px;float:left;width:27px;height:20px;background-size: contain;background-repeat: no-repeat;" alt="student">
</div>
#endif

Laravel dom pdf image issue

I am using dompdf in laravel to create invoice. and it works fine for me until i use image in that.
Admin Controller
public function generateInvoice(Request $request)
{
$user = Auth::user();
$pdf = PDF::loadView('pdf.invoice', $user);
return $pdf->download('invoice.pdf');
}
And in Invoice View Page that contains the invoice template...
<style>
.block{
display: block;
}
.minifont12{
font-size: 12px;
}
.minifont10{
font-size: 10px;
}
.col-md-45{
width: 45%;
display: inline-block;
}
.col-md-30{
width: 30%;
display: inline-block;
}
.col-md-25{
width: 24%;
display: inline-block;
}
.bluecolor{
background-color: #C5C5EC;
}
.midtop{
margin-top: 50px;
}
</style>
<div class="header" style="position:relative; top:10; width:100%; ">
<img src="http://localhost:8000/img/minilogo.jpg">
<div style="text-align:center; margin-top:-20px;">Retail Invoice/Bill</div>
<div style="text-align:right">Invoice No. #BTR_PB_000052</div>
</div>
<div class="content">
<div class="minifont12 block" style="margin-top:20px;">
<strong>Sold By:</strong> SRM Smart Solutions Pvt. Ltd.<br>
<span class="minifont10">
Building No. 29, Third Floor, Central Market, West Punjabi Bagh, Delhi-110026
</span>
</div>
<hr>
<div class="col-md-45">
Order Id : BT121178273<br>
Order Date : 24-05-2016<br>
Invoice Date : 25-05-2016<br>
CIN No. : U72300DL2015PTC281652
</div>
<div class="col-md-30">
Avinash<br>
H.No 30-45-5/26, Chandigari colony east, rohit cottage lane, opp. krupa comlex lane, r.k.puram post, 500 056, hdy.<br>
Hyderabad, telangana - 500056<br>
8099473211
</div>
<div class="col-md-25">
<span class="midtop bluecolor">
*Keep this invoice for return and refund purposes
</span>
</div>
</div>
but When I run the code...it will show error message
Maximum execution time of 60 seconds exceeded
Please tell me what is the issue behind this..
I had the same issue when using a very large image. I solved the issue by changing the maximum execution time by adding this line before starting the pdf creation: ini_set('max_execution_time', 120);. You can also change this in your php.ini file if you like, just make sure you know what you're doing, as this setting applies to all scripts executed on your web server. You'll also have to restart your web server after making changes in the php.ini file.
Some other options so solve this are discussed here.
you can use this code :
<img src="{{ public_path("images/a.png") }}">
or can :
<div style="background: url({{ public_path("images/a.png"}})">text</div>

Image sprite - form submit button

Can i use image sprites for my form submit button, tried a few things but nothing seems to work.
.button, .download, .OK, .file{
background: url(app/sprites.png) no-repeat;
}
.button{
background-position: -1px -212px ;
width: 170px;
height: 30px;
}
My form
<form action="add.php" method="post" value="Username">
<div style="float:left; margin-left:15px;"><input type="text" name="fbid" required></div>
<div style="float:left; margin-left:2px;"><input type="submit" value="Submit"></form>
Right now you are missing a class on the input.
<input type="submit" class="button" value="Submit">
With that it'll work.
I put it into a jsFiddle, using a different image because I don't have access to yours. You can play with the position, in incriments of 32px.
jsfiddle.net/CzWCv
Have you tried
<div class="button" style="float:left; margin-left:2px;"><input type="submit"
value="Submit"></form>
??

jquery ajax form submit plugin not posting file input

I've got this form:
<form id="imageinputpopup" class=suggestionsubmit style="display: none">
<span>Add a thing!</span><br/>
<label>url: </label><input name="imageurl" type="url"><br/>
<label>file: </label><input name="imagefile" type="file"><br/>
<input type='hidden' name='schoolid' class="schoolid">
<input type="submit" value="Submit">
</form>
And this document.ready:
<script type="text/javascript">
$(document).ready(function() {
$('.schoolid').val(get_gmap_value('school_id'));
$(".allow-submission").live('click', function(){
if($(this).attr('inputtype')=="colorpicker"){
.....
} else if($(this).attr('inputtype')=="image"){
remove_hidden("#imageinputpopup");
add_fieldname($(this), $("#imageinputpopup"));
$("#imageinputpopup").dialog();
} else if($(this).attr('inputtype')=="text"){
....
} else {
//nothing
}
});
$(".suggestionsubmit").submit(function(){
event.preventDefault();
alert($(this).html());
$(this).ajaxSubmit({
url: '/save-school-suggestion/',
type: 'post',
success: function(response){
response = jQuery.parseJSON(response);
// Check for login redirect.
// if ( response.requireLogin ) {
// alert('Sign up or log in to save your answer');
// } else {
$('.suggestionsubmit').dialog('close');
// }
}
});
});
});
function add_fieldname(element, addto){
var elementname = document.createElement('input');
elementname.type = 'hidden';
elementname.name = 'fieldname';
elementname.value = element.attr('fieldname').replace(' ', '_');
$(elementname).addClass('fieldname');
addto.append(elementname);
}
function remove_hidden(element){
$(element+' .fieldname').remove();
}
But the file field isn't showing up server side.
Why?
I found this in the documentation:
Why aren't all my input values posted?
jQuery form serialization aheres closely to the HTML spec. Only successful controls are valid for submission.
But I don't understand why my file control would be invalid.
I have another submission form in a different place on my site that is almost identical and works perfectly...
EDIT: this is the other form that does work (it has some extra stuff in it, but the form tag just has an id, like the problem one, and the input tags are the same).
<form id="photos-submission-form6">
<input type="hidden" name="section" value="photos">
<input type="hidden" name="school" id="photos-submit-school6">
<div style="margin-bottom: .5em">
<p style="position: relative; width:80%; font-size: 14px; display: inline" id="photos-anonymity-header6">Post as: null</p>
<img id="helpicon6" src="/static/img/help-icon.png" style="float: right; cursor: pointer; padding-left:1em;">
<div id="explanation6" style="display: none; padding:1em; background-color:white; border:2px solid gray; position: absolute;z-index:30; right:5px; top:5px">For more posting options, <a id="profilelink6" href="/profile/">fill out your profile</a></div>
</div>
<div id="photos-anonymity-select6" style="margin-bottom: .75em; width:412px" class="ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all"><a class="ui-slider-handle ui-state-default ui-corner-all" href="#" style="left: 100%; "></a></div>
<input type="hidden" id="photos-anonymity-level6" name="anonymity-level" value="username">
<span style="line-height: 40px;">
<label class="photouploadlabel">URL</label><input type="text" name="image-url" style="width: 335px"><br>
<label class="photouploadlabel">File</label><input type="file" name="image-file" style="width: 335px"><br>
<label class="photouploadlabel">Caption</label><input type="text" id="image-caption6" name="image-caption" style="width: 335px; color: rgb(128, 128, 128); ">
</span>
<div style="height: 30px; margin-top: 1em; width: 413px;">
<label id="photos-tagsbutton6" style="margin-right: .5em; cursor: pointer; vertical-align: bottom; float:left; line-height: 1.8em;">Tags</label>
<input id="photos-tagsinput6" style="display: none;" type="text" name="tags">
<button id="send-photos-suggestion6" disabled="" style="float:right; position: relative; bottom: 7px; right: -4px;" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-disabled ui-state-disabled ui-button-text-only" role="button" aria-disabled="true"><span class="ui-button-text">Post</span></button>
</div>
</form>
This is probably not the case but are sure there are no spelling mistake server side? like you would be using $_FILE instead of $_FILES? Could you post the relevant php also?
Also, definitely not an issue but it is recommended to close your input tags, now like this:
<input ... />
Add enctype="multipart/form-data" attribute to your form.
Try to change the type of the input imageurl from url to text:
FROM:
<label>url: </label><input name="imageurl" type="url"><br/>
TO:
<label>url: </label><input name="imageurl" type="text"><br/>
I am not sure, but maybe the jquery plugin fails serializing the form due to invalid type attribute of image_url.
Hey you just forgot to add ---> enctype="multipart/form-data" in the form tag. This will help you out.
I think you have a problem with the binding in javascript not recognising your file.
Try binding your submit trigger event with another live() function
i.e. change
$(".suggestionsubmit").submit(mooFar(e));
to
$(".suggestionsubmit").live('submit', mooFar(e));
...........I was looking in the wrong place in the request for the file.
Server side should have been:
if not s.url_field and 'imagefile' in request.FILES:
s.image_field = request.FILES['imagefile']
instead of
s.image_field = request.POST.get('imagefile', None)
Complete and utter fail on my part.
Make sure the files you're testing aren't outside the max file size, it would be worth setting this in your HTML.
<input type="hidden" name="MAX_FILE_SIZE" value="500" />
Also, testing without the display:none might be worth while until you have the form working; which browser are you testing in?

Resources