logo
down
shadow

Laravel: where condition based on db field


Laravel: where condition based on db field

By : Tobias
Date : November 22 2020, 01:01 AM
Does that help How to make a whereclause that is based on an existing field in the database, and not on an input parameter? , You need to use...
code :
where('column1', '=', DB::raw('column2'));


Share : facebook icon twitter icon
Choosing rows based on grouping condition and field condition

Choosing rows based on grouping condition and field condition


By : 김종철
Date : March 29 2020, 07:55 AM
around this issue Using dplyr this could be done. But aggregate could also be used.
Edit: using a new dataset to handle this test case of containing both HB and KU.
code :
options(scipen = 50)
library(dplyr)
ss <- read.table(text = "       plot ID             tree
                 1    10000503711            LV
                 2  1000057448111            LV
                 3  1000057448111            HB
                 4  1000057448111            KU
                 5    10000603711            LV
                 5    10000603711            HB
                 6  1000063448111            TM
                 7  1000063448111            KS", header = T)


ss %>% 
  group_by(ID) %>% 
  mutate(trees = paste0(tree, collapse = "_")) %>%
  filter(grepl('HB_KU|KU_HB',trees)) %>%  distinct(ID) %>% 
  inner_join(.,ss)
Joining, by = "ID"
# A tibble: 3 x 3
# Groups:   ID [?]
             ID  plot   tree
          <dbl> <int> <fctr>
1 1000057448111     2     LV
2 1000057448111     3     HB
3 1000057448111     4     KU
How to show same field based on an or condition on alpaca by binding a field to multiple dependencies

How to show same field based on an or condition on alpaca by binding a field to multiple dependencies


By : Chunze Chen
Date : March 29 2020, 07:55 AM
this will help Why you don't use a group of checkboxes using enum type like the following :
code :
// schema
"check": {
    "title": "Select...",
    "type": "string",
    "enum": ["First", "Second"]
},
...
// options
"check": {
    "type": "checkbox"
}
"username": {
   "dependencies": {
      "check": [
          'First', // if First is selected
          'Second', // if Second is selected
          'First,Second' // if both First and Second are selected
      ] 
   }
}
redirect to different views in laravel logged in users based on role mentioned by using if condition in laravel controll

redirect to different views in laravel logged in users based on role mentioned by using if condition in laravel controll


By : Takorn Aekkittipawon
Date : March 29 2020, 07:55 AM
This might help you You better create a middleware to check user role, and based on the role redirect user to different pages!
Run the command below to create a middleware that checks user's role.
code :
php artisan make:middleware CheckRoleMiddleware
<?php namespace App\Http\Middleware;

use Closure;

class CheckRoleMiddleware {

    public function handle($request, Closure $next)
    {
        //User role is admin
        if ( Auth::check() && Auth::user()->isAdmin() )
        {
            return $next($request);
        }

        //If user role is student
        if(Auth::check() && auth()->user()->role === 'student')
        {
             return view('studentDashboard');
             or route('routeName');
        }

        //If user role is teacher
        if(Auth::check() && auth()->user()->role ==='teacher')
        {

             return view('teacherDashboard');
             or route('routeName');

        }
        //default redirect
        return redirect('home');

    }

}
protected $routeMiddleware = [
    'auth' => 'App\Http\Middleware\Authenticate',
    'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
    'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
    'user-role' => 'App\Http\Middleware\CheckRoleMiddleware', // this line right here
];
update a specific dataframe field based on a condition involving a different field + iteration

update a specific dataframe field based on a condition involving a different field + iteration


By : Yasam
Date : March 29 2020, 07:55 AM
wish of those help Idea is create MultiIndex by DataFrame.set_index in columns for groups, here Obj_col1 and Obj_col2, then set values by conditions and last reset_index for original indices:
code :
print (df)
   Obj_col1 Obj_col2 Obj_col3  Num_col1  Num_col2  Num_col3    Month
0         A       AB       XY        74        40        97  2018-04
1         A       AB       XY        61        26        29  2018-12
2         A       AB       XY        50        75        92  2019-03
3         A       AB       XY        33        99        87  2019-04
4         B       AB       XY        74        40         7  2018-04
5         B       AB       XY        61        26         1  2018-12
6         B       AB       XY        50        75         9  2019-03
7         B       AB       XY        33        99         8  2019-04
8         C       AB       XA        74        40         9  2018-04
9         C       AB       XA        61        26         1  2018-12
10        C       AB       XA        50        75        92  2019-03
11        C       AB       XA        33        99        87  2019-04
df = df.set_index(['Obj_col1','Obj_col2'])

m1 = (df['Obj_col3'] == 'XY') & (df['Month'] == '2018-12')
m2 = (df['Obj_col3'] == 'XY') & (df['Month'] == '2018-04')
df.loc[m2, 'Num_col2'] = df.loc[m1, 'Num_col3'] * 1000 # * 2 in real data 

df = df.reset_index()
print (df)
   Obj_col1 Obj_col2 Obj_col3  Num_col1  Num_col2  Num_col3    Month
0         A       AB       XY        74     29000        97  2018-04
1         A       AB       XY        61        26        29  2018-12
2         A       AB       XY        50        75        92  2019-03
3         A       AB       XY        33        99        87  2019-04
4         B       AB       XY        74      1000         7  2018-04
5         B       AB       XY        61        26         1  2018-12
6         B       AB       XY        50        75         9  2019-03
7         B       AB       XY        33        99         8  2019-04
8         C       AB       XA        74        40         9  2018-04
9         C       AB       XA        61        26         1  2018-12
10        C       AB       XA        50        75        92  2019-03
11        C       AB       XA        33        99        87  2019-04
def f(x):
    m1 = (x['Obj_col3'] == 'XY') & (x['Month'] == '2018-12')
    m2 = (x['Obj_col3'] == 'XY') & (x['Month'] == '2018-04')
    x.loc[m2, 'Num_col2'] = (x.loc[m1, 'Num_col3'] * 1000).values
    return x

df = df.groupby(['Obj_col1','Obj_col2']).apply(f)
Set value of data frame new field equal to another field based on condition on a third field in R

Set value of data frame new field equal to another field based on condition on a third field in R


By : DisplayName=
Date : March 29 2020, 07:55 AM
like below fixes the issue If I want to add a field to a given data frame and setting it equal to an existing field in the same data frame based on a condition on a different (existing) field. , Using data.table it's quite easy
Related Posts Related Posts :
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • What's wrong with my PHP Script? T_String issue
  • how to call a function of another file without including that file
  • is_rgb function in php
  • transform the numbers to letters using php
  • How to catch an exception from another class method PHP
  • PHP exec is blocked by ISP
  • PHP4 to PHP5 migration character encoding. latin1 vs utf8
  • Begin Transaction not defined
  • How much harm can a user do with xss on a page unique to them?
  • How to import data from a php file to javascript variable
  • PHP and Javascript - log complete workflow
  • When I echo !!! 0 it gives me a strange result
  • jquery ajax post dies after submit
  • How to upload file with curl on sftp server
  • Advanced search using a text input to search through only one category
  • Why do I get "Non-static method App\Models\Category::products() should not be called statically" in laravel
  • Stop notices from undefined indexes in arrays
  • PHP Excel Error when entering SUM function to a cell
  • laravel 4 eloquent eager load relation count
  • click submit in html and run php code
  • Extremely frustrating behavior with Internet Explorer, Bootstrap and Respond.js
  • Vkontakte vtag issues
  • Divide the number to a correct decimal
  • mysqli_insert_query not working
  • How to make a sitemap using zend framework 1
  • Laravel: array to Model with relationship tree
  • $_SERVER['DOCUMENT_ROOT'] vs $path = $_SERVER['DOCUMENT_ROOT']
  • What is the best way to store multiple checkbox values in the database and work with it later on
  • Why does foreach copy the array when we did not modify it in the loop?
  • Receive Jquery/Ajax Post Request in PHP
  • How to better use the if(!empty()){ //codes} statement
  • PHP error mysql_close() boolean given
  • Move an image file from one server to another using PHP
  • PHP: Encoding non ISO-8859-1 charactrers into utf8
  • Handling MySQL errors in PHP
  • Object orientated mysql num_rows query in one line
  • Remove not closed html elements from end of text
  • Generate random ENUM value [PHP, MySQL]
  • Deleting data from table using jQuery and SQL
  • How to make sure the constructor is executed when I'm trying to reach a static property?
  • Trying to understand arrow next to PHP function
  • Form using external php file to show "Sucess"
  • WooCommerce - new shipping method - how to query individual product weights
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org