score:0
in queries defined by db::select()
you can use parameters defined in array.
$sql = db::select(db::raw("
select orders.id,
// ...
where tr.tenant_relations_type = 'app\\models\\order'
and orders.created_at between :datefrom and :dateto
// ...
"), [
'datefrom' => $request->input('dateform'),
'dateto' => $request->input('dateto'),
]);
of course you should additionally filter input dates to make sure are in valid format.
score:0
use bindings for the variables
$startdate = '2021-01-01 00:00:00';
$enddate = '2021-06-07 00:00:00';
$sql= db::select(db::raw(
"
select orders.id,
//... rest of the query ommited
where tr.tenant_relations_type = ?
and orders.created_at between ? and ? and
//... rest of the query ommited
", [order::class, $startdate, $enddate]));//place your variables in order here
if you dont want to track the order of the bindings, you can use an associative array.
$sql= db::select(db::raw(
"
select orders.id,
//... rest of the query ommited
where tr.tenant_relations_type = :model
and orders.created_at between :start and :end and
//... rest of the query ommited
"; ['start' => $startdate, 'end' => $enddate, 'model' => order::class]));
Source: stackoverflow.com
Related Query
- Variables in MySql raw queries
- Variables in graphQL queries
- Send 2 identical Graphql queries in one call but with different variables
- CSS modules with SASS variables in media queries
- Passing variables through to GraphQL queries in external queries.ts file in React
- Passing variables for media queries and rendering css in styled components?
- Concatenating variables and strings in React
- Rendering raw html with reactjs
- react evironment variables .env return undefined
- Instance v state variables in react.js
- How to set build .env variables when running create-react-app build script?
- How to define css variables in style attribute in React and typescript
- Media queries in MUI components
- React Hooks - using useState vs just variables
- Create React App: using environment variables in index.html
- Storing non-state variables in functional components
- How can I add raw data body to an axios request?
- How to concatenate two JSX fragment or variables or string and component (in Reactjs)?
- JavaScript and ES6, "global" variables
- React Apollo - Make Multiple Queries
- react-testing-library - Screen vs Render queries
- add raw HTML with <script> inside Gatsby React page
- Can't access gatsby environment variables on the client side
- Destructuring Variables Performance
- Accessing previous theme variables in createMuiTheme
- How to use environment variables in Github Page?
- How to access environment variables from the front-end
- Next.JS: Using SASS variables from global scss
- How to use environment variables in React app hosted in Azure
- Global scss variables in react-create-app
More Query from same tag
- Filter images in React with JavaScript
- Working with DOM elements in react testing-library?
- Can't perform React state update on an unmounted component on making go to top btn
- Getting onClick eventargs for the parent of e.target & Adding custom data to propagating onClick args
- Unable to get updated cache in component in a server rendered nextjs apollo app
- How to add flex-box to React Rating?
- multiple Redux-form with formValueSelector
- DraftJS - contentState.getBlockMap is not a function
- How to play a wav (loaded from a URL) in React/html5?
- Mock api calls from Storybook
- ReactJS is not being able to map an array
- How do I make sure null and empty string fields arent added to my documents in firestore Reactjs
- How can I render my popup component over a Container or Div instead of below to it
- React error: TypeError: render is not a function
- React: How to hit API only once using useEffect
- How to Normalize state in redux using Normalizr
- How can I remove a chip from a controlled autocomplete?
- event.target.value is undefined for buttons that wrap an image instead of text
- How to know if the props already exists ReactJS?
- How can I make tx.executeSql() function sync with async/await?
- Changing state of object nested in array of objects
- How do I test an element that is outside the enzyme wrapper?
- Dealing with "Selected" Option in ReactJS
- How do I push items or maybe add an element in array of array
- Create a Controller
- Question on .this binding within a React Component
- Error when running jest on a react native + typescript app (Jest encountered an unexpected token)
- React Bootstrap Popover: Pre-Open Popover on initialization
- npm start is giving webpack cli error with React.js
- Cannot figure out how to customize a D3 based plot