I have 10 images. im inserted that 10 images into database.then im tring to insert one more image.i want to one error message "only 10 images are occur" how to check database limit and input no of count?using laravel can you give validation code using laravel
my write controller.php is here
if(ForumGallery::count>=5)
{return "only 5 images";}
else
{ return Redirect::route('addgallery');}
but an error occur
http://Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR)
Undefined class constant 'count'
my validation part
$validate=Validator::make(Input::all(),array(
'galname'=>'required|max:20',
'galimg'=>'required|max:200kb|Mimes:jpeg,jpg,gif,png
,pneg',
));
In Laravel eloquent, to return count use:
$max_image = 5;
if(ForumGallery::all()->count() <= $max_image)
{
ForumGallery::create($input); //call the function to upload image here
return Redirect::route('addgallery');
}
else
{
return "max image upload reached!";
}
Controller.php page
public function getgallery()
{
$validate=Validator::make(Input::all(),array(
'galname'=>'required|max:20',
'galimg'=>'required|max:200kb|Mimes:jpeg,jpg,gif,png
,pneg',
));
if($validate->fails())
{
return Redirect::route('getgallery')
->withErrors($validate)->withInput();
}
else
{
$file=Input::file('galimg');
$filename=$file->getClientOriginalName();
//->getClientOriginalExtension();
//$file->move('uploads',$filename);
// ForumGallery::create([
// 'galname'=>Input::get('galname'),
// 'galimg'=>$filename
// ]);
$max_image = 2;
if(ForumGallery::all()->count() < $max_image)
{
$file->move('uploads',$filename);
ForumGallery::create([
'galname'=>Input::get('galname'),
'galimg'=>$filename
]);//call the function to upload image here
return Redirect::route('addgallery');
}
else
{
return "max image upload reached!";
}
}
return Redirect::route('gallery');
}
Related
there is my code:
protected function room_count($room_count)
{
$query = $this->builder
->whereJsonContains('rent_requests.rooms_count', $room_count);
return $query;
}
There is my filter function. $room_count is array, and for example can be [2,4].
rent_requests.rooms_count is JSON array in MySQL, and it can be for example [2,3].
I need to filter this, to get this advert showed, but whereJSONContains expects that there will be 2 and 4, not 2 or 4.
Is there any tricks to make this function work correctly ? Something like json contains whereIn ?)
Sorry for my english, im really stuck on this, please help me :)
MySQL and PostgreSQL support whereJsonContains with multiple values:
So if you are using either of the database then you can pass $room_count as the second parameter
// Room Count Filter
protected function room_count($room_count)
{
return $this->builder
->where(function($query) use($room_count){
$query->whereJsonContains('rent_requests.rooms_count', $room_count[0]);
for($i = 1; $i < count($room_count); $i++) {
$query->orWhereJsonContains('rent_requests.rooms_count', $room_count[$i]);
}
return $query;
});
}
Laravel docs: https://laravel.com/docs/8.x/queries#json-where-clauses
but #donkarnash function is slightly changed, here is the final version with this example for those who face the same problem
// Room Count Filter
protected function room_count($room_count)
{
return $this->builder
->where(function($query) use($room_count) {
$query->whereJsonContains('rent_requests.rooms_count', $room_count[0]);
info (count($room_count));
for($i = 1; $i <= count($room_count) - 1; $i++) {
$query->orWhereJsonContains('rent_requests.rooms_count', $room_count[$i]);
}
return $query;
});
}
I am trying to catch an error thrown by my Web API in Angular, and I want to display a user-friendly error message in certain cases. How would I access the string "PE and Owner Signature must be attached for a status of Submitted", given the response body below?
{
"data": {
"model.WorkflowStepId": [
"PE and Owner Signature must be attached for a status of Submitted"
]
},
"exceptionType": "FieldValidation"
}
This is what I have so far, but I'm stuck since I am currently only displaying the string "model.WorkflowSetId".
this.spinner = this.certService.updateCert(this.damId, this.certId, this.model)
.subscribe(response => {
...
},
(errorRes: HttpErrorResponse) => {
if (errorRes.error && errorRes.error.exceptionType === 'FieldValidation') {
const errors = errorRes.error.data;
for(let error in errors)
this.notificationService.error(error);
} else {
console.log(errorRes);
this.notificationService.error('An unknown error has occurred. Please try again.');
}
});
You may simply do:
if (errorRes.error && errorRes.error.exceptionType === 'FieldValidation') {
this.notificationService.error(errorRes.error.data.model.WorkflowStepId[0]);
}
So it turns out that "model.WorkflowStepId" was actually a string. To capture it and other types of validation errors I was able to loop through bad requests, build a string that grouped the same types of field validation errors into single messages, and display those messages to the user using the toaster.
if (errorRes.error && errorRes.error.exceptionType === 'FieldValidation') {
for (var key in errorRes.error.data) {
for (var i = 0; i < errorRes.error.data[key].length; i++) {
errorStr += (errorRes.error.data[key][i]);
errorStr += ". ";
}
this.notificationService.error(errorStr);
}
}
I am working on adding and deleting a set of fields in a row, i am able to do this via the following code,
but will have to limit it to a certain number, how would i be able to do that? Thanks in advance
The below is the code.
I am using an array and then using add and delete function for
Component File
`
get formArr(){
return this.finDetailsForm.get('itemRows') as FormArray;
}
initItemRows(){
return this.fb.group({
acc_name: '',
inv_amt: '',
v_inv_date: '',
});
}
addNewRow(){
this.formArr.push(this.initItemRows());
}
deleteRow(index: number) {
this.formArr.removeAt(index);
}
Attaching an image below of it
you can count length of array before push element.
addNewRow(){
if(this.formArr.lenght < 5){
this.formArr.push(this.initItemRows());
}
}
You have 2 solutions:
Update your component function as below:
class YourComponent {
private static MAX_ITEMS = << a number >>;
// ... constructor and rest ...
addNewRow(): void {
if (this.formArr.length < YourComponent.MAX_ITEMS) {
return;
}
this.formArr.push(this.initItemRows());
}
or you simply hide the button "+" when you reached the maximum item you want:
your-component.ts
get maxItemsReached(): boolean {
return this.formArr.length >= YourComponent.MAX_ITEMS;
}
your-component.html
<input type="button" *ngIf="!maxItemsReached">Add</input>
I'm using laravel 5.4, in my User.php file I want to write a function like this :
public function isAdmin(Request $request)
{
if ($request->user()->id == 1) {
return true;
}
}
The function I want to use in my middleware and my blade file. How to write this ?
Now it's giving me this error :
Type error: Argument 1 passed to App\User::isAdmin() must be an
instance of Illuminate\Http\Request, none given, called in
/home/mohib/MEGA/Projects/saifullah-website/app/Http/Middleware/isAdmin.php
on line 18
If you want to find out if the currently authenticated user is an Administrator, based on your logic, you could do something like this:
In App\User.php
public function isAdmin()
{
if ($this->id == 1)
{
return true;
}
return false;
}
and then, you can use it like this:
if(Auth::check() && Auth::user()->isAdmin())
{
// do something here
}
I currently have some code from here (https://github.com/jmhnilbog/Nilbog-Lib-AS2/blob/master/mx/mx/remoting/NetServiceProxy.as) which converts a function into a function. This code is shown below:
private var _allowRes:Boolean= false;
function __resolve( methodName:String ):Function {
if( _allowRes ) {
var f = function() :Object {
// did the user give a default client when he created this NetServiceProxy?
if (this.client != null) {
// Yes. Let's create a responder object.
arguments.unshift(new NetServiceProxyResponder(this, methodName));
}
else {
if (typeof(arguments[0].onResult) != "function") {
mx.remoting.NetServices.trace("NetServices", "warning", 3, "There is no defaultResponder, and no responder was given in call to " + methodName);
arguments.unshift(new NetServiceProxyResponder(this, methodName));
}
}
if(typeof(this.serviceName) == "function")
this.serviceName = this.servicename;
arguments.unshift(this.serviceName + "." + methodName);
return( this.nc.call.apply(this.nc, arguments));
};
return f;
}
else {
return null;
}
}
Basically what the code is designed to do is return a new function (returned as f) which performs the correct server operates. However, if I try and use this syntax in AS3, I get the following two errors:
Error: Syntax error: expecting semicolon before colon.
Error: Syntax error: else is unexpected.
How would I go about doing this? I know this is someone else's code, but I am trying to get the old AS1/2 mx.remoting functionality working in AS3. Cheers.