本文整理汇总了PHP中app\models\Product::scope方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::scope方法的具体用法?PHP Product::scope怎么用?PHP Product::scope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::scope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: archive
public function archive($publicId)
{
$product = Product::scope($publicId)->firstOrFail();
$product->delete();
Session::flash('message', trans('texts.archived_product'));
return Redirect::to('company/products');
}
示例2: archive
public function archive($publicId)
{
$product = Product::scope($publicId)->firstOrFail();
$product->delete();
Session::flash('message', trans('texts.archived_product'));
return Redirect::to('settings/' . ACCOUNT_PRODUCTS);
}
示例3: process
public function process()
{
$account = Auth::user()->account;
$products = Product::scope()->orderBy('product_key')->limit(5)->get()->transform(function ($item, $key) use($account) {
$card = $item->present()->skypeBot($account);
if ($this->stateEntity(ENTITY_INVOICE)) {
$card->addButton('imBack', trans('texts.add_to_invoice', ['invoice' => '']), trans('texts.add_product_to_invoice', ['product' => $item->product_key]));
}
return $card;
});
return $this->createResponse(SKYPE_CARD_CAROUSEL, $products);
}
示例4: save
public function save($data, $product = null)
{
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
if ($product) {
// do nothing
} elseif ($publicId) {
$product = Product::scope($publicId)->firstOrFail();
\Log::warning('Entity not set in product repo save');
} else {
$product = Product::createNew();
}
$product->fill($data);
$product->save();
return $product;
}
示例5: save
private function save($productPublicId = false)
{
if ($productPublicId) {
$product = Product::scope($productPublicId)->firstOrFail();
} else {
$product = Product::createNew();
}
$product->product_key = trim(Input::get('product_key'));
$product->notes = trim(Input::get('notes'));
$product->cost = trim(Input::get('cost'));
$product->default_tax_rate_id = Input::get('default_tax_rate_id');
$product->save();
$message = $productPublicId ? trans('texts.updated_product') : trans('texts.created_product');
Session::flash('message', $message);
return Redirect::to('settings/' . ACCOUNT_PRODUCTS);
}
示例6: save
private function save($productPublicId = false)
{
if ($productPublicId) {
$product = Product::scope($productPublicId)->firstOrFail();
} else {
$product = Product::createNew();
}
$product->product_key = trim(Input::get('product_key'));
$product->notes = trim(Input::get('notes'));
$product->cost = trim(Input::get('cost'));
//$product->default_tax_rate_id = Input::get('default_tax_rate_id');
$product->save();
$transformer = new ProductTransformer(\Auth::user()->account, Input::get('serializer'));
$data = $this->createItem($product, $transformer, 'products');
return $this->response($data);
}
示例7: getViewModel
private static function getViewModel()
{
// Tax rate $options
$account = Auth::user()->account;
$rates = TaxRate::scope()->orderBy('name')->get();
$options = [];
$defaultTax = false;
foreach ($rates as $rate) {
$options[$rate->rate . ' ' . $rate->name] = $rate->name . ' ' . ($rate->rate + 0) . '%';
// load default invoice tax
if ($rate->id == $account->default_tax_rate_id) {
$defaultTax = $rate;
}
}
return ['entityType' => ENTITY_QUOTE, 'account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(['product_key', 'notes', 'cost', 'qty']), 'taxRateOptions' => $options, 'defaultTax' => $defaultTax, 'countries' => Cache::get('countries'), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Cache::get('currencies'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'languages' => Cache::get('languages'), 'industries' => Cache::get('industries'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'invoiceFonts' => Cache::get('fonts'), 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'isRecurring' => false];
}
示例8: findPhonetically
public function findPhonetically($productName)
{
$productNameMeta = metaphone($productName);
$map = [];
$max = SIMILAR_MIN_THRESHOLD;
$productId = 0;
$products = Product::scope()->with('default_tax_rate')->get();
foreach ($products as $product) {
if (!$product->product_key) {
continue;
}
$map[$product->id] = $product;
$similar = similar_text($productNameMeta, metaphone($product->product_key), $percent);
if ($percent > $max) {
$productId = $product->id;
$max = $percent;
}
}
return $productId && isset($map[$productId]) ? $map[$productId] : null;
}
示例9: getViewModel
private static function getViewModel()
{
return ['entityType' => ENTITY_QUOTE, 'account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'countries' => Cache::get('countries'), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Cache::get('currencies'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'industries' => Cache::get('industries'), 'invoiceDesigns' => InvoiceDesign::availableDesigns(), 'invoiceLabels' => Auth::user()->account->getInvoiceLabels()];
}
示例10: showClientPortal
/**
* @return \Illuminate\Contracts\View\View
*/
private function showClientPortal()
{
$account = Auth::user()->account->load('country');
$css = $account->client_view_css ? $account->client_view_css : '';
if (Utils::isNinja() && $css) {
// Unescape the CSS for display purposes
$css = str_replace(['\\3C ', '\\3E ', '\\26 '], ['<', '>', '&'], $css);
}
$types = [GATEWAY_TYPE_CREDIT_CARD, GATEWAY_TYPE_BANK_TRANSFER, GATEWAY_TYPE_PAYPAL, GATEWAY_TYPE_BITCOIN, GATEWAY_TYPE_DWOLLA];
$options = [];
foreach ($types as $type) {
if ($account->getGatewayByType($type)) {
$options[$type] = trans("texts.{$type}");
}
}
$data = ['client_view_css' => $css, 'enable_portal_password' => $account->enable_portal_password, 'send_portal_password' => $account->send_portal_password, 'title' => trans('texts.client_portal'), 'section' => ACCOUNT_CLIENT_PORTAL, 'account' => $account, 'products' => Product::scope()->orderBy('product_key')->get(), 'gateway_types' => $options];
return View::make('accounts.client_portal', $data);
}
示例11: getViewModel
private static function getViewModel()
{
$recurringHelp = '';
foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) {
$parts = explode("=>", $line);
if (count($parts) > 1) {
$line = $parts[0] . ' => ' . Utils::processVariables($parts[0]);
$recurringHelp .= '<li>' . strip_tags($line) . '</li>';
} else {
$recurringHelp .= $line;
}
}
return ['data' => Input::old('data'), 'account' => Auth::user()->account->load('country'), 'products' => Product::scope()->with('default_tax_rate')->orderBy('id')->get(), 'countries' => Cache::get('countries'), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Cache::get('currencies'), 'languages' => Cache::get('languages'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'industries' => Cache::get('industries'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'frequencies' => array(1 => 'Weekly', 2 => 'Two weeks', 3 => 'Four weeks', 4 => 'Monthly', 5 => 'Three months', 6 => 'Six months', 7 => 'Annually'), 'recurringHelp' => $recurringHelp, 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'tasks' => Session::get('tasks') ? json_encode(Session::get('tasks')) : null];
}
示例12: handleBuyNow
public function handleBuyNow(ClientRepository $clientRepo, InvoiceService $invoiceService, $gatewayTypeAlias = false)
{
if (Crawler::isCrawler()) {
return redirect()->to(NINJA_WEB_URL, 301);
}
$account = Account::whereAccountKey(Input::get('account_key'))->first();
$redirectUrl = Input::get('redirect_url', URL::previous());
if (!$account || !$account->enable_buy_now_buttons || !$account->hasFeature(FEATURE_BUY_NOW_BUTTONS)) {
return redirect()->to("{$redirectUrl}/?error=invalid account");
}
Auth::onceUsingId($account->users[0]->id);
$product = Product::scope(Input::get('product_id'))->first();
if (!$product) {
return redirect()->to("{$redirectUrl}/?error=invalid product");
}
$rules = ['first_name' => 'string|max:100', 'last_name' => 'string|max:100', 'email' => 'email|string|max:100'];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return redirect()->to("{$redirectUrl}/?error=" . $validator->errors()->first());
}
$data = ['currency_id' => $account->currency_id, 'contact' => Input::all()];
$client = $clientRepo->save($data);
$data = ['client_id' => $client->id, 'tax_rate1' => $account->default_tax_rate ? $account->default_tax_rate->rate : 0, 'tax_name1' => $account->default_tax_rate ? $account->default_tax_rate->name : '', 'invoice_items' => [['product_key' => $product->product_key, 'notes' => $product->notes, 'cost' => $product->cost, 'qty' => 1, 'tax_rate1' => $product->default_tax_rate ? $product->default_tax_rate->rate : 0, 'tax_name1' => $product->default_tax_rate ? $product->default_tax_rate->name : '']]];
$invoice = $invoiceService->save($data);
$invitation = $invoice->invitations[0];
$link = $invitation->getLink();
if ($gatewayTypeAlias) {
return redirect()->to($invitation->getLink('payment') . "/{$gatewayTypeAlias}");
} else {
return redirect()->to($invitation->getLink());
}
}
示例13: getViewModel
private static function getViewModel($invoice)
{
$recurringHelp = '';
$recurringDueDateHelp = '';
$recurringDueDates = [];
foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) {
$parts = explode('=>', $line);
if (count($parts) > 1) {
$line = $parts[0] . ' => ' . Utils::processVariables($parts[0]);
$recurringHelp .= '<li>' . strip_tags($line) . '</li>';
} else {
$recurringHelp .= $line;
}
}
foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_due_date_help')) as $line) {
$parts = explode('=>', $line);
if (count($parts) > 1) {
$line = $parts[0] . ' => ' . Utils::processVariables($parts[0]);
$recurringDueDateHelp .= '<li>' . strip_tags($line) . '</li>';
} else {
$recurringDueDateHelp .= $line;
}
}
// Create due date options
$recurringDueDates = [trans('texts.use_client_terms') => ['value' => '', 'class' => 'monthly weekly']];
$ends = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th'];
for ($i = 1; $i < 31; $i++) {
if ($i >= 11 && $i <= 13) {
$ordinal = $i . 'th';
} else {
$ordinal = $i . $ends[$i % 10];
}
$dayStr = str_pad($i, 2, '0', STR_PAD_LEFT);
$str = trans('texts.day_of_month', ['ordinal' => $ordinal]);
$recurringDueDates[$str] = ['value' => "1998-01-{$dayStr}", 'data-num' => $i, 'class' => 'monthly'];
}
$recurringDueDates[trans('texts.last_day_of_month')] = ['value' => '1998-01-31', 'data-num' => 31, 'class' => 'monthly'];
$daysOfWeek = [trans('texts.sunday'), trans('texts.monday'), trans('texts.tuesday'), trans('texts.wednesday'), trans('texts.thursday'), trans('texts.friday'), trans('texts.saturday')];
foreach (['1st', '2nd', '3rd', '4th'] as $i => $ordinal) {
foreach ($daysOfWeek as $j => $dayOfWeek) {
$str = trans('texts.day_of_week_after', ['ordinal' => $ordinal, 'day' => $dayOfWeek]);
$day = $i * 7 + $j + 1;
$dayStr = str_pad($day, 2, '0', STR_PAD_LEFT);
$recurringDueDates[$str] = ['value' => "1998-02-{$dayStr}", 'data-num' => $day, 'class' => 'weekly'];
}
}
// Tax rate $options
$account = Auth::user()->account;
$rates = TaxRate::scope()->orderBy('name')->get();
$options = [];
$defaultTax = false;
foreach ($rates as $rate) {
$options[$rate->rate . ' ' . $rate->name] = $rate->name . ' ' . ($rate->rate + 0) . '%';
// load default invoice tax
if ($rate->id == $account->default_tax_rate_id) {
$defaultTax = $rate;
}
}
// Check for any taxes which have been deleted
if ($invoice->exists) {
foreach ($invoice->getTaxes() as $key => $rate) {
if (isset($options[$key])) {
continue;
}
$options[$key] = $rate['name'] . ' ' . $rate['rate'] . '%';
}
}
return ['data' => Input::old('data'), 'account' => Auth::user()->account->load('country'), 'products' => Product::scope()->with('default_tax_rate')->orderBy('product_key')->get(), 'taxRateOptions' => $options, 'defaultTax' => $defaultTax, 'currencies' => Cache::get('currencies'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'invoiceFonts' => Cache::get('fonts'), 'frequencies' => [1 => trans('texts.freq_weekly'), 2 => trans('texts.freq_two_weeks'), 3 => trans('texts.freq_four_weeks'), 4 => trans('texts.freq_monthly'), 5 => trans('texts.freq_three_months'), 6 => trans('texts.freq_six_months'), 7 => trans('texts.freq_annually')], 'recurringDueDates' => $recurringDueDates, 'recurringHelp' => $recurringHelp, 'recurringDueDateHelp' => $recurringDueDateHelp, 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'tasks' => Session::get('tasks') ? json_encode(Session::get('tasks')) : null, 'expenseCurrencyId' => Session::get('expenseCurrencyId') ?: null, 'expenses' => Session::get('expenses') ? Expense::scope(Session::get('expenses'))->with('documents', 'expense_category')->get() : []];
}
示例14: getViewModel
private static function getViewModel()
{
$recurringHelp = '';
foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) {
$parts = explode("=>", $line);
if (count($parts) > 1) {
$line = $parts[0] . ' => ' . Utils::processVariables($parts[0]);
$recurringHelp .= '<li>' . strip_tags($line) . '</li>';
} else {
$recurringHelp .= $line;
}
}
$recurringDueDateHelp = '';
foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_due_date_help')) as $line) {
$parts = explode("=>", $line);
if (count($parts) > 1) {
$line = $parts[0] . ' => ' . Utils::processVariables($parts[0]);
$recurringDueDateHelp .= '<li>' . strip_tags($line) . '</li>';
} else {
$recurringDueDateHelp .= $line;
}
}
// Create due date options
$recurringDueDates = array(trans('texts.use_client_terms') => array('value' => '', 'class' => 'monthly weekly'));
$ends = array('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th');
for ($i = 1; $i < 31; $i++) {
if ($i >= 11 && $i <= 13) {
$ordinal = $i . 'th';
} else {
$ordinal = $i . $ends[$i % 10];
}
$dayStr = str_pad($i, 2, '0', STR_PAD_LEFT);
$str = trans('texts.day_of_month', array('ordinal' => $ordinal));
$recurringDueDates[$str] = array('value' => "1998-01-{$dayStr}", 'data-num' => $i, 'class' => 'monthly');
}
$recurringDueDates[trans('texts.last_day_of_month')] = array('value' => "1998-01-31", 'data-num' => 31, 'class' => 'monthly');
$daysOfWeek = array(trans('texts.sunday'), trans('texts.monday'), trans('texts.tuesday'), trans('texts.wednesday'), trans('texts.thursday'), trans('texts.friday'), trans('texts.saturday'));
foreach (array('1st', '2nd', '3rd', '4th') as $i => $ordinal) {
foreach ($daysOfWeek as $j => $dayOfWeek) {
$str = trans('texts.day_of_week_after', array('ordinal' => $ordinal, 'day' => $dayOfWeek));
$day = $i * 7 + $j + 1;
$dayStr = str_pad($day, 2, '0', STR_PAD_LEFT);
$recurringDueDates[$str] = array('value' => "1998-02-{$dayStr}", 'data-num' => $day, 'class' => 'weekly');
}
}
return ['data' => Input::old('data'), 'account' => Auth::user()->account->load('country'), 'products' => Product::scope()->with('default_tax_rate')->orderBy('product_key')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Cache::get('currencies'), 'languages' => Cache::get('languages'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'industries' => Cache::get('industries'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'invoiceFonts' => Cache::get('fonts'), 'frequencies' => array(1 => 'Weekly', 2 => 'Two weeks', 3 => 'Four weeks', 4 => 'Monthly', 5 => 'Three months', 6 => 'Six months', 7 => 'Annually'), 'recurringDueDates' => $recurringDueDates, 'recurringHelp' => $recurringHelp, 'recurringDueDateHelp' => $recurringDueDateHelp, 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'tasks' => Session::get('tasks') ? json_encode(Session::get('tasks')) : null, 'expenses' => Session::get('expenses') ? json_encode(Session::get('expenses')) : null, 'expenseCurrencyId' => Session::get('expenseCurrencyId') ?: null];
}
示例15: index
/**
* @return \Illuminate\Http\Response
*/
public function index()
{
$products = Product::scope()->withTrashed()->orderBy('created_at', 'desc');
return $this->listResponse($products);
}